Commands & Syntax > Commands > Macro Flow Control >

www.MacroToolworks.com

WAIT FOR - < waitfor >() ... [Free]

 

WAIT FOR
<waitfor>("Object","Event","Parameter",Timeout (seconds),Exact)
Available in: Free edition

Wait for a special event (window, clipboard, key, mouse) to occur.

 

#

Parameter name

Parameter description

1

Object

Can be one of these:
"WIN" - a window related event is expected
"CLIP" - a clipboard related event is expected
"KEY" - a specific key press is expected
"MOUSE" - a mouse click is expected
"IMAGE_ON_SCREEN_EXACT" - an image on screen will appear/disappear, image must be exactly the same
"IMAGE_ON_SCREEN_TOLERANT" - an image on screen will appear/disappear, image does not has to be exactly the same - some level of tolerance is allowed
"WEBBROWSER" - Internet Explorer web browser is loading data
"FILE" - a file is created or deleted
"FOLDER" - a folder is created or deleted

2

Event

These events are supported for particular Object:
"WIN" :
- "OPEN" - wait until the window specified by Param is opened.
- "CLOSE" - wait until the window specified by Param is closed.
- "ACT" - wait until the window specified by Param is activated.
- "NOACT" - wait until the window specified by Param is deactivated.
"CLIP" :
- "EMPTY" - wait until the clipboard is emptied.
- "SET" - wait until some data are put into the clipboard.
"KEY" :
- "" (key is pressed) - wait until some of the keys specified by Param is pressed.
"MOUSE" :
- "" (mouse click) - wait until mouse click specified by Param appears.
"IMAGE_ON_SCREEN_EXACT"
- "APPEAR" - wait until the image appears on screens
- "DISAPPEAR" - wait until the image disappears from screens
"IMAGE_ON_SCREEN_TOLERANT"
- "APPEAR" - wait until the image appears on screens
- "DISAPPEAR" - wait until the image disappears from screens
"WEBBROWSER"
- "LOADING" - wait until the web page is fully loaded
"FILE"
- "CREATE" - wait until the file is created
- "DELETE" - wait until the file is deleted
- "CHANGED" - wait until the file is changed (based on the last write time)
- "CAN_READ" - wait until the file can be open for reading (after it was previously blocked by some process)
- "CAN_WRITE" - wait until the file can be open for writing (after it was previously blocked by some process)
"FOLDER"
- "CREATE" - wait until the folder is created
- "DELETE" - wait until the folder is deleted

3

Parameter

Has this meaning depending on the Object:
"WIN" - window title
"CLIP" - not used
"KEY" - can be one or more keys. For example, if Param is "abc<F6>KC:27<alt>" the "waitfor" waits until either a or b or c or F6 or ESC or Alt key is pressed. The KC:XXX is a key code number of a key on keyboard. The KC:XXX is showing in the main window in lower right area as keys are being hit. This way the user can know what is key code of each keyboard key.
"MOUSE" - can be one of these:
<mlbu> - left mouse button
<mmbu> - middle mouse button
<mrbu> - right mouse button
"IMAGE_ON_SCREEN_EXACT" - file path to the .bmp file with the image.
"IMAGE_ON_SCREEN_TOLERANT" - file path to the .bmp file with the image.
"WEBBROWSER" - web page URL.
"FILE" - (full) path to the file.
"FOLDER" - (full) path to the file.

4

Timeout (seconds)

Timeout in seconds. If 0, the command never timeouts. If the command timeouts then _vErr system variable is set.

5

Exact

Used only for "WIN" Object. If 1, the window title must exactly match the Param. If 0, the Param can be a substring of a window title.

 

Example (Macro Steps):

 

1

<#> <#> This macro shows how to use 'waitfor' command

2

Macro execution: ONLY COMMANDS

3

Message SHOW "" : "Press 'Ctrl' key to continue this macro." (other parameters: x = 100, y = 100, Window title = Message, Buttons = None, Timeout (seconds) = , Always on top = ).

4

WAIT FOR Object = "KEY", Event = "", Parameter = "", Timeout (seconds) = "5", Exact = "0"

5

Message CLOSE

6

Message SHOW "" : "Press left mouse button to continue this macro." (other parameters: x = 100, y = 100, Window title = Message, Buttons = None, Timeout (seconds) = , Always on top = ).

7

WAIT FOR Object = "MOUSE", Event = "", Parameter = "", Timeout (seconds) = "5", Exact = "0"

8

Message CLOSE

9

Message SHOW "" : "Macro is finished." (other parameters: x = 100, y = 100, Window title = Message, Buttons = OK, Timeout (seconds) = , Always on top = ).

Example (Plain Text):

 

<#> This macro shows how to use 'waitfor' command

<#>

<cmds>

<msg>(100,100,"Press 'Ctrl' key to continue this macro.","Message",0)

<waitfor>("KEY","","<ctrl>",5,0)

<msgoff>

<msg>(100,100,"Press left mouse button to continue this macro.","Message",0)

<waitfor>("MOUSE","","<mlbu>",5,0)

<msgoff>

<msg>(100,100,"Macro is finished.","Message",1)