MonitorGetPrimary() Function Returns Non-primary Monitor # Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

MonitorGetPrimary() Function Returns Non-primary Monitor #

28 Jun 2020, 17:26

Why is it saying my Primary monitor is "3", when my system says "1"? Might this be because before setting Monitor #1 to be my main display in system display settings, my computer defaults to monitor #3 being primary? Even if that's the case, is this odd behavior? And why would my system default Monitor #3 to being the primary one? Just seems funky

code:

Code: Select all

monitorInfo := ""
MonitorCount := MonitorGetCount()
MonitorPrimary := MonitorGetPrimary()

Loop( MonitorCount )
	monitorInfo .=	"Monitor Name:`t" MonitorGetName( A_Index ) "`n`nMonitor Number`t#" A_Index "`n`n"	
	
MsgBox( monitorInfo "`n`nPrimary Monitor=`t#" MonitorPrimary )
output:

Image


Thanks for reading.
-TL
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: MonitorGetPrimary() Function Returns Non-primary Monitor #

28 Jun 2020, 22:33

Are you saying that if you select "3" in Display Settings, the option "Make this my main display" is NOT ticked?
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: MonitorGetPrimary() Function Returns Non-primary Monitor #

29 Jun 2020, 01:46

It works for me as expected.
Image

If I select the first monitor as default, it will be displayed in ahk as well.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: MonitorGetPrimary() Function Returns Non-primary Monitor #

29 Jun 2020, 15:37

lexikos wrote:
28 Jun 2020, 22:33
Are you saying that if you select "3" in Display Settings, the option "Make this my main display" is NOT ticked?
correct.

when I select monitor 1, the option "Make this my main display" is ticked.

I decided to test this by selecting each other monitor (monitor 2 and 3) and ticking the option "Make this my main display".

When I made Monitor 2 my Main Display and ran the code in the OP, Primary Monitor returned as #2 as expected, however when I made Monitor 3 my Main Display and ran the code in OP, Primary Monitor returned as #1 instead of my selection of Monitor 3.

Result when I selected Monitor 3 as Main Display:
Image
-TL
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: MonitorGetPrimary() Function Returns Non-primary Monitor #  Topic is solved

29 Jun 2020, 16:46

AutoHotkey numbers monitor by the order they are returned from the OS function EnumDisplayMonitors. In your case, that coincides with the actual system names of the monitors (DISPLAY1, DISPLAY2, DISPLAY3). I have no idea how Display Settings numbers them, but it seems the fault lies there, since the numbers are inconsistent with the names.

Experience and some searching tells me:
  • Display Settings numbers the monitors according to some internal algorithm nobody knows.
  • It has nothing to do with which output the video card/BIOS considers primary.
  • Rebooting the system with only one monitor connected might cause the numbering to change.
  • Disabling and re-enabling monitors in Device Manager might cause the numbering to change.
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: MonitorGetPrimary() Function Returns Non-primary Monitor #

01 Jul 2020, 20:33

lexikos wrote:
29 Jun 2020, 16:46
AutoHotkey numbers monitor by the order they are returned from the OS function EnumDisplayMonitors. In your case, that coincides with the actual system names of the monitors (DISPLAY1, DISPLAY2, DISPLAY3). I have no idea how Display Settings numbers them, but it seems the fault lies there, since the numbers are inconsistent with the names.

Experience and some searching tells me:
  • Display Settings numbers the monitors according to some internal algorithm nobody knows.
  • It has nothing to do with which output the video card/BIOS considers primary.
  • Rebooting the system with only one monitor connected might cause the numbering to change.
  • Disabling and re-enabling monitors in Device Manager might cause the numbering to change.
Thank you for the explanation. Fortunately, despite the numbering being off, my scripts are still working as needed so its not a huge deal.

I will update when I test your above ideas and see if I get any different results. Much appreciated.
-TL

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Quixilvr, V4Friend and 41 guests