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.

5807 views

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.

Tell us what you think:

  1. How to create a list of selectable items with AutoIt.
  2. Tutorial on how to make GUIs using the AutoIt scripting language.
  3. How to disable and enable AutoIt GUI elements using GUICtrlSetState.
  4. How to interrupt running functions and handle system events in AutoIt GUI scripting.
  5. Tutorial on how to add images to AutoIt GUIs while maintaining aspect ratio.

More in: AutoIt GUIs