Pregunta

Im trying to click different images that pops up in a flash game but my script isnt working properly.

Sometimes it works the way it should, though sometimes the cursor just moves up to the left corner and stays there for some reason.

What could I be doing wrong?

Heres my code:

#include <ImageSearch.au3>

HotKeySet("{F7}", "Start")
HotKeySet("{ESC}","Stop")

$X = 0
$Y = 0
$X1 = 0
$Y1 = 0

Func Start()
    While 1
        $Search = _ImageSearch('pic1.bmp',0,$X,$Y,10)
        $Search1 = _ImageSearch('pic2.bmp',0,$X,$Y,10)
        If $Search = 1 Then
            MouseMove($X, $Y,5)
            MouseClick("Left")
        ElseIf $Search1 = 1 Then
            MouseMove($X1, $Y1,5)
            MouseClick("Left")
        EndIf
        Sleep(200)
    WEnd
EndFunc

Func Stop()
    Exit
EndFunc

While 1 
    Sleep(200)
WEnd

Also is it possible to recognize "images" that are moving is this, or a similiar way?

¿Fue útil?

Solución

Not sure but I think you need to add this line.

Start()
Func Start()

Also change this

$Search = _ImageSearch('pic1.bmp',0,$X,$Y,10)
$Search1 = _ImageSearch('pic2.bmp',0,$X,$Y,10)

MouseMove($X, $Y,5)
MouseClick("Left")

To this.

$Search = _ImageSearch("pic1.BMP",0,$X,$Y,50)
$Search1 = _ImageSearch("pic2.BMP",0,$X1,$Y1,50)

MouseClick("Left", $X, $Y, 1, 5)
MouseClick("Left", $X1, $Y1, 1, 5)

Otros consejos

ImageSearch can find moving pictures but you need to optimize its search area.

  • Use _ImageSearchArea to narrow the search down.
  • Experiment with your search pictures (make them as small as possible)
  • Experiment with variations (This can be a reason for your mouse acting strange)
  • Eventually, use PixelSearch instead.

Here:

$Search1 = _ImageSearch('pic2.bmp',0,$X,$Y,10)

change above to this:

$Search1 = _ImageSearch('pic2.bmp',0,$X1,$Y1,10)

and it will work fine.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top