Obtain Monitor Model And Index

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JohnTravolski
Posts: 21
Joined: 22 Dec 2015, 15:10

Obtain Monitor Model And Index

Post by JohnTravolski » 26 Mar 2023, 16:09

I want a hotkey to move windows to a specific monitor, specifically my "LG HDR 4K" monitor, as it is displayed in Windows. The problem is that I have only figured out to do this using monitor indexes, and every time I unplug or re-plug in the monitors, the indexes seem to jump around.

I was hoping I could do it by name, rather than an index, so I tried this:

Code: Select all

SysGet, MonitorCount, MonitorCount
Loop, %MonitorCount%
{
  SysGet, MonitorName, MonitorName, %A_Index%
  MsgBox, Monitor %A_Index%: %MonitorName%
}
But the monitor names aren't helpful; they are "\\.\DISPLAY1", ""\\.\DISPLAY2", ""\\.\DISPLAY3", etc. I assume those indexes will also change when I unplug the monitors and everything.

How can I tell authotkey to move a window specifically to the "LG HDR 4K" monitor, even as I plug in new monitors or unplug other monitors arbitrarily?

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Obtain Monitor Model And Index

Post by mikeyww » 26 Mar 2023, 16:11

Hi,

There are posts about it. I would search forum for "multi-monitor" and also look up @JoeWinograd.

JohnTravolski
Posts: 21
Joined: 22 Dec 2015, 15:10

Re: Obtain Monitor Model And Index

Post by JohnTravolski » 26 Mar 2023, 18:47

mikeyww wrote:
26 Mar 2023, 16:11
Hi,

There are posts about it. I would search forum for "multi-monitor" and also look up @JoeWinograd.
The one I found still refers to them with an index rather than by name. Maybe I'm not looking at the right thing? This is what I found:

https://www.experts-exchange.com/articles/33932/Keyboard-shortcuts-hotkeys-to-move-mouse-in-multi-monitor-configuration-AutoHotkey-Script.html

User avatar
mikeyww
Posts: 26937
Joined: 09 Sep 2014, 18:38

Re: Obtain Monitor Model And Index

Post by mikeyww » 26 Mar 2023, 19:24

Right. That's my only idea here! Perhaps Joe will reply.

User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Obtain Monitor Model And Index

Post by JoeWinograd » 26 Mar 2023, 21:04

Hi John,

The one that you found is my major (but not only) contribution to the multi-monitor world, and you are right...it does not have the names as Device Manager shows them (nor do any of my other contributions). Of course, Device Manager doesn't always show it...here's what it shows on my 4-monitor config:

monitor names.png
monitor names.png (3.02 KiB) Viewed 263 times

So, only one of the four has a "correct" name...even the HP Pavilion 32 shows as generic (while the HP Omen 32 gets a description...go figure).

I've never tried to figure out how to get the Device description property (my scripts don't need it), which is what you're looking for (*IF* your LG HDR 4K has that in the field):

device description property.png
device description property.png (13.71 KiB) Viewed 263 times

Maybe these Microsoft links will help (I haven't studied them carefully enough to know):

https://learn.microsoft.com/en-us/windows/desktop/api/Winuser/nf-winuser-enumdisplaydevicesa
https://learn.microsoft.com/en-us/windows/desktop/api/Winuser/nf-winuser-enumdisplaymonitors
https://learn.microsoft.com/en-us/windows/desktop/api/Winuser/nf-winuser-getmonitorinfoa

Or maybe these forum threads (also not studied carefully):

viewtopic.php?f=76&t=7762
viewtopic.php?f=6&t=4606

An Idea: If you have only one 4K monitor, use the coordinates coming back from SysGet (left, right, top, bottom) to figure out which one is the LG 4K. That's easy!

Regards, Joe

Post Reply

Return to “Ask for Help (v1)”