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

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
User avatar
Tigerlily
Posts: 365
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: 7201
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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: 2681
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
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] 1.1.33.02 x64 Unicode | [WIN] 10 Pro (Version 20H2) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
Tigerlily
Posts: 365
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: 7201
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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: 365
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 “AutoHotkey v2 Help”

Who is online

Users browsing this forum: Kapitano and 8 guests