# WinWaitActive / WinWaitNotActive

Waits until the specified window is active or not active.

WinWaitActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
WinWaitNotActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]

#### Parameters

WinTitle | The title or partial title of the target window (the matching behavior is determined by SetTitleMatchMode). If this and the other 3 window parameters are blank or omitted, the Last Found Window will be used. To use a window class, specify ahk_class ExactClassName (shown by Window Spy). To use a process identifier (PID), specify ahk_pid %VarContainingPID%. To use a window group, specify ahk_group GroupName. To use a window's unique ID number, specify ahk_id %VarContainingID%. The search can be narrowed by specifying multiple criteria. For example: My File.txt ahk_class Notepad
WinText | 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.
Seconds | How many seconds to wait before timing out and setting ErrorLevel to 1. Leave blank to wait indefinitely. Specifying 0 is the same as specifying 0.5. This parameter can be an expression.
ExcludeTitle | Windows whose titles include this value will not be considered.
ExcludeText | Windows whose text include this value will not be considered.

#### 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 Seconds 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.

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

#### Related

WinWait, WinWaitClose, IfWinExist, IfWinActive, SetTitleMatchMode, DetectHiddenWindows

#### Example

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