WinWaitActive / WinWaitNotActive

Waits until the specified window is active or not active.

WinWaitActive WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText
WinWaitNotActive WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText



Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.


Type: String

If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.


Type: Integer or Float

How many seconds to wait before timing out and returning 0. Leave blank to allow the function to wait indefinitely.


Type: String

Windows whose titles include this value will not be considered.


Type: String

Windows whose text include this value will not be considered.

Return Value

Type: Integer

WinWaitActive returns the HWND (unique ID) of the active window if it matches the criteria, or 0 if the function timed out.

WinWaitNotActive returns 1 if the active window does not match the criteria, or 0 if the function timed out.


If the active window satisfies the function's expectation, the function will not wait for Timeout to expire. Instead, it will immediately return, allowing the script to resume.

Since "A" matches whichever window is active at any given moment, WinWaitNotActive "A" typically waits indefinitely. To instead wait for a different window to become active, specify its unique ID as in the following example:

WinWaitNotActive WinExist("A")

Both WinWaitActive and WinWaitNotActive will update the Last Found Window if a matching window is active when the function begins or becomes active while the function is waiting.

While the function is in a waiting state, new threads can be launched via hotkey, custom menu item, or timer.

If another thread changes the contents of any variable(s) that were used for this function's parameters, the function will not see the change -- it will continue to use the title and text that were originally present in the variables when the function first started waiting.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.


WinWait, WinWaitClose, WinExist, WinActive, SetTitleMatchMode, DetectHiddenWindows



Run "notepad.exe"
if WinWaitActive("Untitled - Notepad", , 2)
    WinMinimize  ; minimize the window found by WinWaitActive.
    MsgBox "WinWaitActive timed out."