Home > Language Reference > Wait Functions > Wait for a Keystroke

Wait for a Keystroke

The Pause until key pressed pauses script execution until the specified key is pressed on keyboard. If after the specified timeout, the specified key is not pressed, the block of statements following PauseFalse keyword is executed.

Usage

Used to wait for a user interaction. For example, a script launches a website, goes to a request page, prompts the user to make the selection he wants and press a key when the selection is done. The script pauses execution until the key is pressed. Use Insert/Wait For/Key menu to generate easily such a Pause.

Syntax

Pause [x secs] until
    Key(<key_list>) 
    [InWindow(<window_name>,<instance>)]
    [InModule(<application_name>)]
[PauseOK|PauseTrue]
 'If the key is pressed, the optional statements after the PauseOK and before the PauseFalse are executed
[PauseFalse]
' After the specified timeout, if the key has not been pressed, the statements after the PauseFalse are executed
     MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
     End
EndPause

Parameters

[x secs], optional. If the key has not been pressed after x seconds, the statements after the PauseFalse keyword are executed. If not specified, the default timeout is the one as defined by #PauseTimeout system variable (default value: 120 seconds). mins can be used instead of secs for a timeout in minutes.

Key, keyword. It specifies in <key_list> the keystrokes to wait. Case is preserved. Special keystrokes (Alt, Shift, ...) must be specified using their keyboard mnemonics.

InWindow, optional keyword. If specified, the condition is met only when the key is pressed within the window specified by <window_name> and its <instance> number. 

InModule, optional keyword. If specified, the condition is met only when the key is pressed within the application specified by <application_name>

See also

Wait for a Date
Wait for Image
Wait for a Menu Selection
Wait for a Mouse Click
Wait for OCR Text
Wait for a Text
Wait for a Time Delay
Wait for a Window

Examples

Pause until
      Key("<Alt <Del>>")
 PauseFalse
      MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
      End
 EndPause

Pause until
     Key("<Shift <Num 2>>")
     InModule("IEXPLORE.EXE")
PauseFalse
     MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
     End
EndPause

Pause until
      Key("r")
      InWindow("IEXPLORE.EXE|Internet Explorer_Server||1",2)
PauseFalse
      MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
      End
EndPause

'Script waiting for a keystroke before going on
StartBrowser("IE", "www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
 ClickHTMLElement("A[INNERTEXT= 'Form']")
UsePage("Form")
'Display a message to tell the user what to do and then press F12 key
msgframe("Please check or uncheck Urgent request checkbox and then press F12",1)

Pause until
     Key("<F12>")
     InModule("IEXPLORE.EXE")
PauseFalse
     MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
     End
EndPause
removeframe(1)
'Test if the checkbox is checked or not
ret=CheckedHTML("INPUT CHECKBOX[NAME= 'contactsoon']")
If ret = 1 then
 msgbox("You did check Urgent request checkbox")
EndIf