Richard Guest
|
Posted: Fri Apr 28, 2006 9:39 am Post subject: Wait for image |
|
|
Found a simple solution to wait for an image. Want to share this:
| Code: |
; Constants
WAIT_FOR_CHECK_INTERVAL=100 ; check every x seconds
WAIT_FOR_MAX_CHECK_LOOPS=70 ; maximum count of checks
IMAGE_SEARCH_TOP_LEFT_X=0 ; x value of top left corner of search rect
IMAGE_SEARCH_TOP_LEFT_Y=0 ; y value of top left corner of search rect
IMAGE_SEARCH_BOTTOM_RIGHT_X=400 ; x value of bottom right corner of search rect
IMAGE_SEARCH_BOTTOM_RIGHT_Y=500 ; y value of bottom right corner of search rect
; Function could be used here
WaitForImage("input_window.bmp");
; Function WaitForImage
WaitForImage(filenameImage) {
global WAIT_FOR_CHECK_INTERVAL
global WAIT_FOR_MAX_CHECK_LOOPS
global IMAGE_SEARCH_TOP_LEFT_X
global IMAGE_SEARCH_TOP_LEFT_Y
global IMAGE_SEARCH_BOTTOM_RIGHT_X
global IMAGE_SEARCH_BOTTOM_RIGHT_Y
loopCount = 0;
Loop {
Sleep, %WAIT_FOR_CHECK_INTERVAL%
ImageSearch, FoundX, FoundY, %IMAGE_SEARCH_TOP_LEFT_X%, %IMAGE_SEARCH_TOP_LEFT_Y%, %IMAGE_SEARCH_BOTTOM_RIGHT_X%, %IMAGE_SEARCH_BOTTOM_RIGHT_Y%, %filenameImage%
if (ErrorLevel = 0)
break ; image found
loopCount += 1
if (loopCount > WAIT_FOR_MAX_CHECK_LOOPS) {
Msgbox Image %filenameImage% not found!
exitApp
}
}
}
|
For the example the bitmap input_window.bmp must be located in the same directory as the script.
Richard |
|