Jump to content

Imagesearch - Keep searching until picture becomes "visible"


SBrix
 Share

Go to solution Solved by JohnOne,

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

  • 6 months later...

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)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...