USB-Soft-KVM is a lightweight Linux solution that turns a simple USB switch into a full-featured KVM solution. By combining an inexpensive USB switch with software-based monitor switching via DDC/CI, you get complete keyboard-video-mouse control on a budget. This software solution automatically switches your monitor’s input source using DDC/CI commands over the I2C bus whenever you toggle the USB switch by responding to USB device connection events. It’s perfect for users with a laptop and desktop sharing one monitor.
https://github.com/mevdschee/usb-soft-kvm
The problem it solves
Hardware KVM switches with integrated monitor switching typically cost much more than basic USB switches, which may cost as little as EUR 10. Many people already use USB switches to share keyboards and mice between two computers, but they’re forced to manually press the monitor’s input button every time they toggle peripherals. USB-Soft-KVM bridges this gap, transforming an inexpensive USB switch into a complete KVM solution by adding automated monitor switching.
How it works
The solution uses udev rules to detect USB device connection and disconnection events. When your keyboard is plugged in (meaning the USB switch is pointing to the desktop), a udev rule triggers a script that sends a DDC/CI command to switch the monitor to DisplayPort. When the keyboard is disconnected (USB switch toggled to the laptop), another udev rule switches the monitor to HDMI. The monitor responds to these commands via the I2C bus that’s already built into your video cable. No extra wiring needed beyond what you already have.
Hardware requirements
You need a monitor with DDC/CI support, which includes most modern displays. The key component is a USB switch to toggle peripherals between computers. Your desktop PC must have I2C bus access, which is standard on Linux systems. The laptop doesn’t need any special configuration since the udev rules only run on the desktop.
Choosing a USB switch
You can choose between two approaches:
- Option 1: USB switch with built-in hub
- Option 2: Bidirectional USB switch (if you already have a hub)
Choose based on your setup: if you already have a hub, a simple bidirectional switch works great. Otherwise, get a switch with built-in hub. Consider how many USB ports you need and whether you require USB 3.0 speeds or if USB 2.0 is sufficient.
Installation and configuration
Setup requires identifying three things: your I2C device path, your monitor’s
input source values, and your keyboard’s USB vendor and product IDs. Running
sudo ddccontrol -p reveals the I2C device and available input sources with
their numeric values. Running lsusb shows your keyboard’s vendor and product
IDs in the format idVendor:idProduct. You edit these values into the udev
rules. The entire process takes less than 5 minutes.
It basically boils down to this one file
/etc/udev/rules.d/90-usb-soft-kvm.rules that contains 04d9 and a231 as the
USB device 16 and 18 as the input sources and dev:/dev/i2c-12 as the
monitor’s I2C device (in my case).
$ cat /etc/udev/rules.d/90-usb-soft-kvm.rules
ACTION=="add", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a231", RUN+="/usr/bin/ddccontrol -r 0x60 -w 16 dev:/dev/i2c-12"
ACTION=="remove", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a231", RUN+="/usr/bin/ddccontrol -r 0x60 -w 18 dev:/dev/i2c-12"
Reliability in practice
The udev rules respond immediately to USB device events, providing almost instant monitor switching when you toggle the USB switch. DDC/CI commands are inherently reliable since they’re part of the VESA standard, though some cheaper monitors may take a second or two to respond. In daily use the switching is seamless enough that you stop thinking about it. Udev events are logged to the system journal, making troubleshooting straightforward if something goes wrong.
Limitations and future work
The most important limitation is that this solution only works with two devices. The current implementation detects the presence or absence of a keyboard to toggle between two predetermined monitor inputs. Supporting three or more devices would require a different approach, where each device would need its own script to change the input source of the monitor. This solution currently only works on a Linux desktop because it relies on direct I2C device access and udev event handling. Also, the desktop PC must remain powered on for switching to work, since that’s where the udev rules run. While the solution is Linux only, the connected laptop may also run Windows or MacOS. Porting the desktop support from Linux to Windows or Mac would be nice follow-up work, also adding a GUI for all 3 major platforms would be a nice addition.
Conclusion
USB-Soft-KVM delivers full KVM functionality by combining a cheap USB switch with software-based monitor switching. This represents significant savings over traditional hardware KVM switches, making it an attractive option for budget-conscious users. If you run Linux on the desktop and have a DDC/CI-capable monitor, the software is free and installation takes less than 5 minutes. It is a joy to use!
Links
- Github - USB-Soft-KVM - source code
- Wikipedia - DDC/CI - Display Data Channel / Command Interface standard
- Github - ddccontrol - Linux tool for monitor control
- FreeDesktop.org - Udev device management
- xpufx - 100% Software KVM switch with a single monitor
- drew.onl - How to swap monitor inputs between two computers (without pressing monitor buttons)