Jump to content
Sign in to follow this  
SBrix

Imagesearch - Keep searching until picture becomes "visible"

Recommended Posts

SBrix

As the title says.

I have been having problems with my script. I want it to keep looking for an image, and if it can't find it then it should wait 5 seconds and try to look for it again.

I am beginner so go easy on me.

My script so far:

#include <imagesearch.au3>

Hotkeyset("s", 'start')
Hotkeyset("x", 'stop')

$x = 0
$y = 0

Func start()
   $search = _imagesearch('1pixel.bmp', 0, $x, $y, 0)
   If $Search = 1 Then
      Mousemove($x, $y,10)
   EndIf
EndFunc

While 1
sleep(5000)
MouseClick("left")
ExitLoop
WEnd

While 1
      $search = _imagesearch('finish.bmp', 0, $x, $y, 0)
   If $Search = 1 Then
      Mousemove($x, $y,10)
      ExitLoop
   EndIf
   If $Search = 0 Then
      Sleep(5000)
   EndIf
WEnd

func stop()
   Exit
EndFunc

Share this post


Link to post
Share on other sites
SBrix

Imagine you opning a video using Windows Media Player. You go into fullscreen and watch the video. When the video is done it automatically go out of fullscreen. Now what I want is for the script to exit Windows Media Player as soon as the video ends. So basically a script that keep searching for the "red x" and when the "red x" becomes visible then moves to that position and click on it.

And perhaps shutdown the computer after doing so.

I just found AutoIT and became interested in it, so I am trying to create small, but useful scripts. I hope I explained it so you can understand.

Share this post


Link to post
Share on other sites
SBrix

Whoops. It seems to be working now. I believe it was a corrupted .bmp file. Sorry for wasting your time  o:) .

Share this post


Link to post
Share on other sites
SBrix

Question. If "$Search" returns with 0, how can I make it go back to the start of the func?

Share this post


Link to post
Share on other sites
JohnOne

It already does.

While 1
      $search = _imagesearch('finish.bmp', 0, $x, $y, 0)
   If $Search = 1 Then
      Mousemove($x, $y,10)
      ExitLoop
   EndIf
   If $Search = 0 Then
      Sleep(5000)
   EndIf
WEnd

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
TrickyDeath

You can use Window handle to close the process instead of clicking on X button to be closed.

It is much better, since as i see you do not use mousecoordmode in your script, so, if the window posicion is change somehow, it will click on worng posicion.

Edit:

Also better cause, if anything pop up on that area, it will get active and will hide your X button, so it will click on the stuff what was pop up.

BTW dont know if you are still watching this forum. :)

Edited by TrickyDeath

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.