Monitor Functions

Functions for retrieving screen resolution and multi-monitor info. Click on a function name for details.

Function Description
MonitorGet Checks if the specified monitor exists and optionally retrieves its bounding coordinates.
MonitorGetCount Returns the total number of monitors.
MonitorGetName Returns the operating system's name of the specified monitor.
MonitorGetPrimary Returns the number of the primary monitor.
MonitorGetWorkArea Checks if the specified monitor exists and optionally retrieves the bounding coordinates of its working area.

Keysharp Monitor Extensions

These functions are Keysharp-specific and are reached through the KS module:

#Import "Ks" { MonitorFromPoint, MonitorGetScale }

MonitorFromPoint

Returns the number of the monitor containing a point.

MonitorNumber := MonitorFromPoint(X, Y)

X and Y are a point in native virtual-desktop coordinates. When the point lies in a gap between displays, the nearest monitor is returned.

MonitorGetScale

Returns one monitor's authored-size scale.

Scale := MonitorGetScale(N)

N is the monitor number. If omitted, the primary monitor is used.

A scale of 1.0 is 100% and 1.5 is 150%. The value maps deliberately authored UI sizes into native screen units.

Note: This is not a screen-coordinate conversion factor and must never be applied to absolute positions.

A_ScreenScale returns the same value for the primary monitor. Code which spans monitors of differing scale should call this function for the monitor it is working with.

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 of the virtual screen:

MsgBox SysGet(78) " x " SysGet(79)

DllCall, Win functions, SysGet

Examples

Displays info about each monitor.

MonitorCount := MonitorGetCount()
MonitorPrimary := MonitorGetPrimary()
MsgBox "Monitor Count:`t" MonitorCount "`nPrimary Monitor:`t" MonitorPrimary
Loop MonitorCount
{
    MonitorGet A_Index, &L, &T, &R, &B
    MonitorGetWorkArea A_Index, &WL, &WT, &WR, &WB
    MsgBox
    (
        "Monitor:`t#" A_Index "
        Name:`t" MonitorGetName(A_Index) "
        Left:`t" L " (" WL " work)
        Top:`t" T " (" WT " work)
        Right:`t" R " (" WR " work)
        Bottom:`t" B " (" WB " work)"
    )
}