With the recent resurgence in Covid19 I’ve been working from home a lot and using both my work laptop and personal PC on the same monitor. HDMI KVM switches start at $150 and I didn’t feel like buying one. So I wrote a script to change inputs on my monitor. The following script locks the session on the local machine and switches the monitor’s input to the other machine. I ran the command “ddcutil vcpinfo| grep Input” which shows that (on my monitor at least) 60 is the VCP for input. Then I ran the command “ddcutil getvcp 60” to get the current value and tried setting values sequentially to find the value for the other port.
Below is the script I’m using on one system, the other is the same but setting the different port via setvcp. The loginctl command is to lock the screen to prevent accidental keyboard or mouse input from messing anything up.
# lock the session, assumes that seat0 is the only session loginctl lock-session $(loginctl list-sessions|grep "seat0 *$"|cut -c1-7) # 0xf is DisplayPort, 0x11 is HDMI-1 ddcutil setvcp 60 0x11
For keyboard, mouse, and speakers I’m using a USB 2.0 hub that I can switch between computers. I idly considered getting a three-pole double-throw switch (four pole switches aren’t available at my local electronic store) to switch USB 2.0 as I only need to switch 3 of the 4 wires. But for the moment just plugging the hub into different systems is enough, I only do that a couple of times a day.
Another implementation of your display switching:
https://github.com/haimgel/display-switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
https://news.ycombinator.com/item?id=29608967
Have you seen https://www.die-welt.net/2021/01/building-a-simple-kvm-switch-for-30eur/ ? My monitor sadly doesn’t properly do the DDC input switching, but I can recommend the UGREEN USB 3.0 Sharing Switch Box (e.g. https://www.amazon.com/UGREEN-Selector-Computers-Peripheral-Switcher/dp/B01N6GD9JO) for doing the USB switching part.
Paul and Jonathan: thanks for those references. Since writing that post I bought a $5 USB switch ($9 including postage) and that seems like a good idea. I’ve also discovered that my monitor supports programming the buttons on the bottom so I programmed one to be HDMI-1 and another to be DisplayPort which is easier than running my script. But getting my script to run from watching USB is even better!