Skip to content

Instantly share code, notes, and snippets.

@labmonkey
Last active May 3, 2024 11:00
Show Gist options
  • Select an option

  • Save labmonkey/5148c9c1706546b2cd711318b9a854af to your computer and use it in GitHub Desktop.

Select an option

Save labmonkey/5148c9c1706546b2cd711318b9a854af to your computer and use it in GitHub Desktop.
My Dual Monitor and Dual PC/Laptop setup. Easy KVM alternative via scripts

Summary

This Guide describes how to have a KVM like solution but cheaper and maybe just good enough for you.

What hardware you need

  1. This works between any Windows machines. I have 1 Windows PC and 1 Windows Laptop.
  2. I am using 2 Monitors where both support at least 2 input sources and they also support DDC/CI (One has 1xDP + 1xHDMI and other 1xDP + 2xHDMI)
  3. I have a PCI-E graphics card in my PC that has multiple outputs. I bought a 4xUSB switch that supports 2 sources and a USB-C -> 2xDP adapter for laptop (as it had only 1 HDMI slot). It is way cheaper to have the devices separate because for some reason KVM devices that support high refresh rate monitors and/or 4K are very expensive while adapters are cheap.

In the end you have 2 deviced connected to both monitors simultaneously (as both monitors have at least 2 inputs, each for each device) and for the keybord, mouse etc. you use a separate USB switch (mine has a physical button but you can also get one that can be triggered by software to make this even more one click solution).

How to get the values

Place your scripts in C:\monitor-source-control\ or wherever you need You need to download the amazing app https://www.nirsoft.net/utils/control_my_monitor.html and place it next to your scripts. Then, run the app and in the GUI read the required values:

  • The unique identifiers of your monitors from the dropdown at top (it should be a 7 character code)
  • For each of the monitor find the VCP code of "Input Select" (in my case 60)
  • Now you have to play around and change the values based on "Possible Values" column
  • After each change you have to press Refresh button on top in order to see the "Current Value"

In the end you can use it similary to this ControlMyMonitor.exe /SetValue ""4JX6X53"" 60 4369. This would set input source as HDMI for my monitor.

Scripts:

Why Visual Basic? Because by using the Wscript.Shell with arguments 0, False at the end it allows you to run a command without any window popping up so its completely in background. You just press a button and only see the result.

  • switch-monitor-1+1.vbs - Set source as my PC for both monitors
  • switch-monitor-1+2.vbs - Set source as my PC for left monitor and Laptop for second monitor
  • switch-monitor-2+2.vbs - Set source as my Laptop for both monitors
  • switch-monitor-2+1.vbs - Set source as my Laptop for left monitor and PC for second monitor

So in my case the values are as follows:

The code for Inpput Source is 60
My left monitor is 4JX6X53 and the HDMI 1 source is 4369 while DP source is 4367
My right monitor is 155HC23 and the HDMI 1 source is 4369 while DP source is 4367
You can see that values for each input have same codes for both monitors (I have 2x DELL)

CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""4JX6X53"" 60 4369"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""155HC23"" 60 4369"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""4JX6X53"" 60 4369"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""155HC23"" 60 4367"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""4JX6X53"" 60 4367"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""155HC23"" 60 4369"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""4JX6X53"" 60 4367"), 0, False
CreateObject("Wscript.Shell").Run("C:\monitor-source-control\ControlMyMonitor.exe /SetValueIfNeeded ""155HC23"" 60 4367"), 0, False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment