Share via:

AutoIt WinActive Function

The WinActive function checks if a window is currently active.


Edited: 2017-03-25 01:54

The AutoIt WinActive function is used to check if a window is currently active. If are looking for a way to activate a window, look up WinActivate instead.

Checking if a window is active can be useful to avoid bogus clicks and key sends. Before input is send you would usually make sure, that the right application window is active.

Use this function in combination with conditional checks, to make your script do whatever you want, depending on the response from WinActive.

To fetch the information you need to identify the right application window, use the AutoIt window info tool that came with AutoIt. Activate the application window, and you'll be able to read the info from the WI tool. See screenshot below:

Screenshot showing the Window tab of the AutoIt Window Info tool.


WindowTitle, hWnd or class of the window to check.
TextThe text of the window to check. Default is an empty string.

Return Value

SuccessThe handle of the window.

WinActive example

; Coordinated to click on screen
$y = 100
$x = 100

If WinActive("[CLASS:SpotifyMainWindow]") Then
  MouseClick("left", $x, $y, 1)

And checking by window title. The following is not the best example, since the title text of the window in Spotify, includes the title of the song you are currently playing, making it unreliable – but it clearly shows the point.

If WinActive("Spotify - some artist – some track name") Then
  MouseClick("left", $x, $y, 1)