MonitorGet()

Auto Hotkey

MonitorGet

Retrieves screen resolution and multi-monitor info.

Exists  := MonitorGet(N, Left, Top, Right, Bottom)
Exists  := MonitorGetWorkArea(N, Left, Top, Right, Bottom)
Count   := MonitorGetCount()
Primary := MonitorGetPrimary()
Name    := MonitorGetName(N)

Parameters

N

The monitor number, between 1 and the number returned by MonitorGetCount(). If omitted, the primary monitor is used.

Left
Top
Right
Bottom

Output variables which receive bounding coordinates as described below.

Exists
Count
Primary
Name

An output variable or the return value of the command, as described below.

MonitorGet

Checks for the existence of monitor number N and optionally retrieves its bounding coordinates. The information is stored in up to four variables passed as parameters. If N is too high or there is a problem retrieving the info, the variables are all made blank and the return value is false. For example:

if MonitorGet(2, Left, Top, Right, Bottom)
    MsgBox, Left: %Left% -- Top: %Top% -- Right: %Right% -- Bottom %Bottom%.
else
    MsgBox, Monitor 2 doesn't exist or an error occurred.

MonitorGetWorkArea

Same as the above except the area is reduced to exclude the area occupied by the taskbar and other registered desktop toolbars.

MonitorGetCount

Retrieves the total number of monitors. Unlike the SM_CMONITORS sub-command of SysGet, the return value includes all monitors, even those not being used as part of the desktop.

MonitorGetPrimary

Retrieves the number of the primary monitor, which will be 1 in a single-monitor system.

MonitorGetName

Retrieves the operating system's name for monitor number N.

Remarks

The built-in variables A_ScreenWidth and A_ScreenHeight contain the dimensions of the primary monitor, in pixels.

SysGet can be used to retrieve the bounding rectangle of all display monitors. For example, this retrieves the width and height:

SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
MsgBox, %VirtualScreenWidth% x %VirtualScreenHeight%

Related

DllCall, WinGet, SysGet

Examples

; This is a working script that displays info about each monitor:
MonitorGetCount, MonitorCount
MonitorGetPrimary, MonitorPrimary
MsgBox, Monitor Count:`t%MonitorCount%`nPrimary Monitor:`t%MonitorPrimary%
Loop, MonitorCount
{
    MonitorGetName, MonitorName, %A_Index%
    MonitorGet, %A_Index%, L, T, R, B
    MonitorGetWorkArea, %A_Index%, WL, WT, WR, WB
    MsgBox, Monitor:`t#%A_Index%`nName:`t%MonitorName%`nLeft:`t%L% (%WL% work)`nTop:`t%T% (%WT% work)`nRight:`t%R% (%WR% work)`nBottom:`t%B% (%WB% work)
}