Add Shortcut Key to Switch Monitor Input Source in Ubuntu 22.04

Have 2 or more PCs connected to a single external monitor? If you run Ubuntu (or other Linux) on one of the PCs, then here’s how to add a keyboard shortcut to switch video source on the monitor.

Most external monitors today have more than one video input ports, e.g., HDMI1, HDMI2, DP1, allowing to connect with different computers at the same time.

And, they usually support DDC/CI protocol to control monitors without hitting physical buttons.

I have multiple computers connected to the single monitor.

To save desktop space, I have only one monitor on my desk, and 2 computers connected to this single monitor. One is running Windows 10 for gaming and another with Ubuntu for work.

In Windows, I use ControlMyMonitor (it’s http link, not sure if it works now) to modify monitor settings and autohotkey to setup keyboard shortcuts.

Advertisements

In Ubuntu and most other Linux, it’s easy to do the job through ddcutil. And, here’s the how to steps one by one.

NOTE: This tutorial should works in all current Ubuntu releases (Ubuntu 20.04, Ubuntu 22.04, Ubuntu 23.04/23.10), and most other Linux, though only tested in 22.04 LTS.

Step 1: Install ddcutil

For Ubuntu user, simply press Ctrl+Alt+T on keyboard to open a terminal window. When it opens, run command to install the command line tool:

sudo apt install ddcutil

Type user password when it asks for sudo authentication, though there’s no asterisk feedback.

For Fedora, RHEL, based systems, run the dnf command below instead:

sudo dnf install ddcutil

And, Arch based Linux can install it via command:

sudo pacman -S ddcutil

Step 2: setup permission

After installing the package above, i2c user group is created. You have to add current user to that group by running command:

sudo gpasswd --add $USER i2c

Not sure if required, but try to restart computer if next step does not work for you.

Step 3: Use Linux command to Switch Monitor Input Source

1. Now, run command in terminal to report connected monitors, and find out the logical display number:

ddcutil detect

In my case, it’s number 1. Usually you can skip this step if only one monitor connected.

2. Next, run command to find out the feature code, as well as its values for input source:

ddcutil --display 1 capabilities

Replace number 1 to yours according to the last command. And you can just skip for --display 1.

In the terminal output, 60 is the input source feature code for me. And, values include: 0f and 11 in hex. So, they are 0x0f and 0x11.

3. After finding out the feature code and its values, try running command to switch monitor input source:

ddcutil setvcp 60 0x11

In this command, replace 60 to yours feature code. And, replace 0x11 (its HDMI-1 in my case) to your values according which video source to switch to.

Step 4: Setup keyboard shortcut to switch input source

If the ddcutil setvcp command works for you, now you may do following steps to set keyboard shortcuts to do the job.

For GNOME (default desktop in Ubuntu & Fedora), open ‘Settings’ and navigate to “Keyboard -> Keyboard Shortcuts -> View and Customize Shortcuts”.

In pop-up dialog, select “Custom Shortcuts”, then add new shortcut with:

  • Name: switch monitor input source (or whatever you want).
  • Command: ddcutil setvcp 60 0x11 (change code 60 & 0x11 according to yours).
  • Shortcut: whatever key combination that you want.

Also, add another keyboard shortcut to switch back.

For other Desktop Environments, try launching “Keyboard Shortcuts”, “Shortcut Keys”, “Custom Shortcuts”, “Keyboard”, etc, for the custom keyboard shortcuts settings page.