Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Wait for image


  • Please log in to reply
No replies to this topic
Richard
  • Guests
  • Last active:
  • Joined: --
Found a simple solution to wait for an image. Want to share this:

; 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