Pause
Synchronization function.
The Pause function waits for an action or for a specified amount of time.
Usage
Used to pause execution of the script until a process has completed. If the process completion time is variable, instead of using an "absolute" pause, prefer to use a wait for a window to appear, a text or a bitmap to be displayed.
For example, the line:
pause 10 ticks
pauses script execution for 10 ticks. A tick is approximately 0.01 secondsSyntax
Wait for a specified amount of time
Pause x Secs|Mins|Ticks|Hours ' a tick is approximately 0.01 sec
[EndPause]Wait for a user action
Pause [x secs] until
Button(<Button>,<Type>) 'wait for a mouse click
or
Key(<key_list>) ' wait for a keyboard action
or
Menu(<menu_item>) ' wait for a selection in a menu
InWindow(<window_name>)
or
InModule("xxx.EXE") ' the keyword "InModule" allows you to synchronize with several windows of the same application.[PauseOK|PauseTrue]
' after the pause condition is met, these statements are executed[PauseFalse]
' If after the specified x secs or if not specified, after #PauseTimeout system variable, the pause condition is not met, the PauseFalse statement is executed
MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
End
EndPauseSynchronizations
Synchronization on Text:
Pause [x secs|ticks] until
Text(<Text>)
InWindow(<window_name>,<instance>)|InWindowAnyInstance((<window_name>)
[InArea(<x>,<y>,<height>,<width>)][PauseOK|PauseTrue]
'pause condition was met
[PauseFalse]
' If after the specified x secs or x ticks, or if not specified, after #PauseTimeout system variable, the pause condition is not met, the PauseFalse statement is executed
MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
End
EndPauseThe optional keyword "InArea" specifies that <Text> must be in a specific area of window <window_name> for the pause to be activated.
If InWindowAnyInstance keyword is used, the <Text> is searched in any instance of <window_name>
Synchronization on OCR Text:
(See Remarks section for a proper usage of this Pause)Pause [x secs] until
TextOCR(<Text> [,<language>])
InWindow(<window_name>)
[InArea(<x>,<y>,<height>,<width>)][PauseOK|PauseTrue]
'pause condition was met
[PauseFalse]
' If after the specified x secs or if not specified, after #PauseTimeout system variable, the pause condition is not met, the PauseFalse statement is executed
MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
End
EndPauseThe optional keyword "InArea" specifies that <Text> must be in a specific area of window <window_name> for the pause to be activated.
At execution, a bitmap capture is done for capturing the specified area within the specified window. The captured bitmap is then submitted at the OCR engine which transforms the bitmap in text. Then the text specified in the TextOCR line is compared to the captured and transformed text at execution. If the same text is found, the Pause triggers. The OCR engine uses the default language of Windows. If <language> is specified in TextOCR line, this language is used (applies only to MODI OCR engine).
Synchronization on an Image:
Pause [x secs|ticks] until
Bitmap(<filename.BMP>)
InWindow(<window_name>)
[InArea(<x>,<y>,<height>,<width>)][PauseOK|PauseTrue]
'pause condition was met
[PauseFalse]
' If after the specified x secs or x ticks, or if not specified, after #PauseTimeout system variable, the pause condition is not met, the PauseFalse statement is executed
MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
End
EndPauseThe optional keyword "InArea" specifies that the bitmap must be in a specific area of window <window_name> for the pause to be activated.
Synchronization on a Window:
Pause [x secs] until
WinStatus(Exists|NotExists|Active|NotActive [,Exact|Near])
InWindow(<window_name>,<instance>)|InWindowAnyInstance(<window_name>)[PauseOK|PauseTrue]
'pause condition was met
[PauseFalse]
' If after the specified x secs, or if not specified, after #PauseTimeout system variable, the pause condition is not met, the PauseFalse statement is executed
MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
End
EndPauseKeyword "WinStatus" specifies the window status which will activate the pause.
If none of keyword "Exact" or "Near" is specified, keyword "Near" is used by default, which means pause will be activated if a window with a name approaching <window_name> is found. If "Exact" is specified, the exact <window_name> must be found in order to activate the pause. You can truncate the window name and still use "Exact" keyword : it will detect a window which window name has the same beginning as the one specified in the InWindow line.
InWindow specifies the <window_name> with its <instance> to look for. If InWindowAnyInstance is used instead of InWindow, the <window_name> whatever its instance is used.
Synchronization on a Date/Time:
Pause until
Date(<date_definition>)
Time(<hour_definition>)EndPause
( Note: the '[x secs|ticks] until' clause is not used with Date or Time definitions)
Parameters
x secs or x ticks is optional ; if not specified, the #PauseTimeout system variable is used. Pause 10 is the same as Pause 10 secs. A tick is around 0.01 second.
The structure :
PauseFalse
MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")
End
displays a dialog box and stops the script execution if the delay x seconds (or #PauseTimeout) has elapsed. If x secs is not specified and if #PauseTimeout=0, the wait is infinite. The structure PauseFalse ... End can be omitted or the statements can be changed as in the example below :
Pause until
Button(left,down)
PauseFalse
If stopimmediate=1 then
stop
else
comment("we write just this message in the logfile "+#ErrorLine$)
endif
EndPause
PauseOK (PauseTrue has the same meaning than PauseOK) and PauseFalse are optional.
Mouse :
<button> : Right or Left
<type> : Up or Down or DoubleMenu :
<menu_item>, for instance &Edit|&Copy<day_definition> : the day (ex : Tuesday) or date in DD-MM-YYYY format (for example : 21-04-2001)
<hour_definition> : time in 24-hour HH:MM format (for example : 13:30)
Remarks
NOTE : If a PAUSE n SECS or n TICKS is the last line just before an UNTIL, the compiler gives an error, so insert the EndPause statement just before the Until.
Pause TextOCR compared to Pause Bitmap : both addresses the case where the text displayed within the window cannot be recognized as pure text. We explain here the advantages and drawbacks of each Pause. A pause TextOCR captures the defined area, submits the image to the OCR engine and the Pause triggers if the OCRerized text is seen - then if the text is not seen, the Pause waits around 1 sec before starting again the recognition attempt. So the main drawback of the Pause TextOCR is that it takes a while, the OCR engine can take up to 3-4 secs. There are 3 advantages compared to a Pause bitmap : no extra file for the captured image, a more readable Pause block as the text is seen in the script and the Pause will work even when you distribute the script on other PCs as the bitmap capture is done at execution.
Pause bitmap at execution captures the defined area and compares it to the specified bmp file. If ticks unit is used in the Pause bitmap, as soon as TaskExec sees that it does not trigger, it captures again and compares again, and so on. So with ticks unit, the Pause bitmap can take up to 100% of CPU but will be very fast to execute. If secs unit is used, when the image is not found, the Pause bitmap waits around 1 sec before starting again to capture the defined area. So whatever ticks or secs unit used, a Pause Bitmap will be always faster than a Pause TextOCR.Examples
Pause until
Date(20-1-2007)
Time(10:16)
EndPause
a$="19-1-2007"
b$="21:06"
Pause until
Date(a$)
Time(b$)
EndPause
Example code
This example shows how to use a wait_text Function to synchronize repeatedly in a script.
Function wait_text(timeout)
local res
res=1
pause timeout seconds until
Text("toto")
InWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
PauseFalse
Res=0
EndPause
wait_text=res
Endfunction
' the function is called as follows :
If wait_text(10)=0 then
...
Else
...
Endif
This example shows how to use a pause_on_two_bmp Function to wait until one of the two specified bmp appears.
function pause_on_two_bmp(win1$,bmp1$,win2$,bmp2$)
local sortie, ret, t
repeat
Pause 1 until
Bitmap(bmp1$)
InWindow(win1$)
PauseOkret=1
EndPause
pause 1 untilBitmap(bmp2$)
InWindow(win2$)
PauseOk
ret=2
EndPause
if ret=0 then
t=t+1
endif
until ret<>0 or t > #PauseTimeout
pause_on_two_bmp=ret
Endfunction
'Call example
win1$="AD-AWARE.EXE|TACimage|Ad-Aware SE Personal|16"
win2$="AD-AWARE.EXE|TACimage|Ad-Aware SE Personal|16"
bmp1$="C:\Program Files\WinTask\Scripts\aaw_next.bmp"
bmp2$="C:\Program Files\WinTask\Scripts\aaw_finish.bmp"
'Maximum timeout before pause on the 2 bmp fails.
#PauseTimeout=400
pause_on_two_bmp(win1$,bmp1$,win2$,bmp2$)
If pause_on_two_bmp=0 then
msgbox("None of the two specified bmp has been found")
End
Endif