By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt WinActive Function

Reference on the WinActivate Function of AutoIt.

Edited: 2015-01-15 22:05

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.

Parameters

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.
Failure0

WinActive example

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

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

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)
EndIf