Home > Language Reference > Program Flow Functions > Sleep

Sleep

The Sleep function makes the current script "sleep" while leaving Event handling active.

Usage

Used to make a script run for ever and stop it through an external event, for example a key pressed by the user.

Syntax

Sleep()

Parameters

None.

Remarks

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.

See also

OnAction

Example

'Use of OnAction/Sleep functions for clicking the OK button of an IE popup window
Sub close()
Disable(popup)
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())
Click(Button,"OK")
stop
endif
Enable(popup)
EndSub

OnAction popup
'OnAction triggers when the popup window appears
WinStatus(Active)
InWindowAnyInstance("IEXPLORE.EXE|#32770|Message from webpage")
DoSub close
EndAction

StartBrowser("IE", "www.wintask.com/demos",3)

UsePage("WinTask Demonstration Pages")
 ClickHTMLElement("A[INNERTEXT= 'Form']")

UsePage("Form")
'Make the popup window appear
 ClickHTMLElement("A[INNERTEXT= 'Popup window']")

sleep()
'Leave the management of the random events active.