The Sleep function makes the current script "sleep" while leaving Event handling active.
Used to make a script run for ever and stop it through an external event, for example a key pressed by the user.
The script is inactive but the OnAction events can still trigger.
If a script launches another script using the Run function, the parent script is "sleeping" until the child script returns control.
A "sleeping" script can be ended inside a sub-routine associated with an event handler, through a Stop or End function, or in another script by the Stop function.
'Use of OnAction/Sleep functions for clicking the OK button of an IE popup window
res=msgbox("Would you like to close the message box? ",4,"EXAMPLE")
if res=6 then
' if res=6, close the popup and stop the script
UseWindow("IEXPLORE.EXE|#32770|Message from webpage",topinstance())
'OnAction triggers when the popup window appears
InWindowAnyInstance("IEXPLORE.EXE|#32770|Message from webpage")
UsePage("WinTask Demonstration Pages")
'Make the popup window appear
ClickHTMLElement("A[INNERTEXT= 'Popup window']")
'Leave the management of the random events active.