By using this site you agree to the use of cookies.

Learn more

Share via:

How to get the Screen Width and Height in AutoIt

How to get the dimension of the screen with AutoIt, both for single and multiple-display monitor environments.

Edited: 2017-02-10 20:53

Knowing the screen resolution of the system where your script is running can be useful when figuring our the screen coordinates for mouse clicks, and when resizing and moving windows.

To get the dimensions of the main screen, you can use the @DeskTopHeight and @DeskTopWidth macros.

MsgBox(0, "Result", @DeskTopWidth & "x" & @DeskTopHeight)

It is not necessary to to save them into variables, since you can access the screen dimensions with the macros whenever you need it.

Multiple monitors

Retrieving the dimensions of multiple monitors can be done using the _WinAPI_ functions, just remember to include the WinAPI.au3 file.

You can get the number of monitors using the _WinAPI_GetSystemMetrics function.

#include <WinAPI.au3>
MsgBox(0, "Result", _WinAPI_GetSystemMetrics(80))

To get the width and height of all monitors combined, you can use the below code.

#include <WinAPI.au3>
MsgBox(0, "Result", _WinAPI_GetSystemMetrics(78) & "x" & _WinAPI_GetSystemMetrics(79))

The problem with this method is that it gives the dimensions of all monitors, which makes it difficult to know the dimensions of individual monitors.