WinWaitActive / WinWaitNotActive

Waits until the specified window is active or not active.

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

Parameters

WinTitle, WinText, ExcludeTitle, ExcludeText

If each of these is blank or omitted, the Last Found Window will be used. Otherwise, specify for WinTitle a window title or other criteria to identify the target window and/or for WinText a substring from a single text element of the target window (as revealed by the included Window Spy utility).

ExcludeTitle and ExcludeText can be used to exclude one or more windows by their title or text. Their specification is similar to WinTitle and WinText, except that ExcludeTitle does not recognize any criteria other than the window title.

Window titles and text are case-sensitive. By default, hidden windows are not detected and hidden text elements are detected, unless changed with DetectHiddenWindows and DetectHiddenText. By default, a window title must start with the specified WinTitle or ExcludeTitle to be a match, unless changed with SetTitleMatchMode.

Timeout

If blank or omitted, the command will wait indefinitely. Otherwise, it will wait no longer than this many seconds. To wait for a fraction of a second, specify a floating-point number, for example, 0.25 to wait for a maximum of 250 milliseconds. Specifying 0 is the same as specifying 0.5. This parameter can be an expression.

ErrorLevel

ErrorLevel is set to 1 if the command timed out or 0 otherwise.

Remarks

If a matching window satisfies the command's expectation, the command will not wait for Timeout to expire. Instead, it will immediately set ErrorLevel to 0 and the script will continue executing.

Both WinWaitActive and WinWaitNotActive will update the Last Found Window if a qualified window is active when the command begins. In addition, WinWaitActive will update the Last Found Window if a qualified window becomes active before the command times out.

While the command 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 command's parameters, the command will not see the change -- it will continue to use the title and text that were originally present in the variables when the command first started waiting.

WinWait, WinWaitClose, WinExist(), WinActive(), SetTitleMatchMode, DetectHiddenWindows

Examples

Opens Notepad and waits a maximum of 2 seconds until it is active. If WinWait times out, an error message is shown, otherwise Notepad is minimized.

Run, notepad.exe
WinWaitActive, Untitled - Notepad,, 2
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
    WinMinimize ; Use the window found by WinWaitActive.