AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wait for image

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Richard
Guest





PostPosted: Fri Apr 28, 2006 9:39 am    Post subject: Wait for image Reply with quote

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group