Talking with the monitor - Part 2 - The Command Line
The Command Line
Most straightforward way to implement this would be a small command line utility, that base on some arguments, just calls the right WIN32 functions. ChatGPT suggests DisplayCommander would be a good name for this utility so I will go with this name.
Here’s the basic usage of the program:
D:\utils>DisplayCommander.exe
DisplayCommander <command> [monitor:[Index|Handle] code:Y [value:Z]]
<command>:
list - lists all the available monitors
caps monitor:[Index|Handle] - outputs the capabilities string for the specified monitor
get monitor:[Index|Handle] code:Y - returns the value for VCP code Y on the specified monitor
set monitor:[Index|Handle] code:Y value Z - sets value Z for VCP code Y on the specified monitor
In Windows, there is this differentiation between (logical) displays and (physical) monitors. Displays are what you have in Control Panel and each display can span on one or more monitors.
The list
command will show the available displays and (physical) monitors:
D:\utils>DisplayCommander.exe list
Index Handle Id Resolution Name
1 0x3D \\.\DISPLAY1 2560x1440 Generic PnP Monitor
2 0x3E \\.\DISPLAY2 1080x1920 HP E24 G4 FHD Monitor
A monitor can be idetified with its index or hex handle. The handle of the monitor can change (usually increases) after some Windows state changes (sleep mode, remote desktop connection, etc.), so it’s not very reliable on a long turn (to be used in a batch file for example). The index is simply the index of the monitor as enumerated by Windows API functions. In theory the order is not guaranteed, but in practice I see it’s quite well preserved, so it’s a better choice for using in batch files.
When specifying the monitor, a decimal number will represent its index and a hex number will represent its handle. Apart from this difference, code and value can be given both as decimal and hex numbers and will have the same meaning.
The get
command reads the value of a certain VCP code for a certain monitor.
D:\utils>DisplayCommander.exe get monitor:1 code:0x60
15
Here, 0x60 is the VESA VCP code for Input Source and 15 is the value meaning the current input source is the Display Port 1 connector, where I have my desktop PC connected.
The set
command is used to switch the input to the laptop, which is connected to the monitor through the USB-C connector:
D:\utils>DisplayCommander.exe set monitor:1 code:0x60 value:16
Now, this is the MVP that I can use to easily change the input source of my monitor from PC to laptop and back, without even touching the hard-to-use joystick on the back of the monitor to navigate through its menus.
Download
The tool can be downloaded from here: DisplayCommander.
Enjoy Reading This Article?
Here are some more articles you might like to read next: