Page 1 of 1

MonitorGetPrimary() Function Returns Non-primary Monitor #

Posted: 28 Jun 2020, 17:26
by Tigerlily
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.

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

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

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

Posted: 29 Jun 2020, 01:46
by jNizM
It works for me as expected.
Image

If I select the first monitor as default, it will be displayed in ahk as well.

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

Posted: 29 Jun 2020, 15:37
by Tigerlily
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

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

Posted: 29 Jun 2020, 16:46
by lexikos
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.

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

Posted: 01 Jul 2020, 20:33
by Tigerlily
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.