If window active/exists

Syntax

ifa[-] window
(tab)statements
(tab)...
[else
(tab)statements
(tab)...]

 

Can be single line:

ifa[-](window) statements
[else statements]

 

Same syntax for ifi.

 

Parameters

window - top-level or child window.

 

Options:

- not.

 

Remarks

Similar to if.

 

ifa: If window is active, execute statements after ifa and skip statements after else (if any). Otherwise, skip statements after ifa and execute statements after else. For child window, tests whether it has focus.

 

ifi: If window exists, execute statements after ifi and skip statements after else (if any). Otherwise, skip statements after ifi and execute statements after else.

 

QM 2.3.3. Can be used as functions. Return 1 if the window is active/exists, 0 if not.

 

See also: wintest

 

Examples

ifa("Notepad") goto lab ;;if window "Notepad" active, go to label "lab"
ifa-("Notepad") bee ;;if window "Notepad" not active, beep
ifi("Notepad") act "Notepad" ;;if window "Notepad" exists, activate it

 If window "Notepad" active, press keys Ctrl+v, else activate Notepad and beep:
ifa "Notepad"
	key Cv
else
	act "Notepad"
	bee

 Can be used as functions
if(ifa("Notepad") or ifa("WordPad")) out "Notepad or WordPad window is active."
if(!ifi("Notepad") and !ifi("WordPad")) out "Notepad and WordPad windows don't exist."