1
votes

Alright so I'm a bit of an Autohotkey noob. I would like to know how to write a script where it will either wait one minute or click after an image is found. I currently know I can use the Sleep feature and the ImageSearch feature, but I don't know how I can combine the two to write the script so that it will continuously check for an image until it's either found and the program will break and continue down, or the image checking has run for a minute, after which it will also break and continue with the program.

So, for example, if the time has been under 1 minute, the program would still be checking for the image. If it is still under a minute and the image has been found, then the program would break and continue. If the time has been over a minute and the image has still not been found, then the program would also break and continue.

I'm a bit stumped with this "either or" thing and I'd appreciate any help! Thanks!

1

1 Answers

1
votes

I'd do it using a loop, and checking the time manually each time. Have a look at the following solution:

TIMEOUT := 6000 ; milliseconds
SLEEP_AFTER_EACH_IMAGESEARCH := 300 ; can be 0

imageFound := false
time_loopStart := A_tickCount
loop {
    imageSearch, ...
    if errorLevel = 0
    {
        imageFound := true
        break
    }
    if(A_tickCount - time_loopStart > TIMEOUT)
        break   ; time is up, no image found in time
    sleep, %SLEEP_AFTER_EACH_IMAGESEARCH%
}
msgbox, imageFound: %imageFound%
return

You could also solve this problem with a Timer. I however would not recommend it. Afaik, it does not save you from measuring the time manually.