Jump to content

Pixel search


Recommended Posts

Here is my script:

Func go()
    $clickpos = MouseGetPos()
    $color = pixelgetcolor ( $clickpos[0] , $clickpos[1] )
    $Findnew = PixelSearch ( 519, 257, 1031, 593, $color )
    if $findnew > 1 then mouseclick ( "left" , $Findnew[0] & $Findnew[1] )
    endfunc

Okay, so im trying to get a color of an object on the screen, then search an area for that color and click on it.

Im a little bit confused on the pixel search parameters. It's really hard to explain what I think it means, but please just explain what it wants

Also, it says that $findnew is a non array variable. Im pretty sure it is. it MAY just be a mistake because i don't know what pixel search wants.

And "if $findnew > 1 then mouseclick" is all i could think of. I know that it most likely doesn't work like that.

And i want it to loop the "if $findnew > 1 then mouseclick" part. Would a "While 1 <func here> Wend" do that? Can I have it in that same function i posted above?

Link to comment
Share on other sites

No errors, but it doesn't click the color.

I think i just need to loop it.

while 1

Wend

right?

You're right, something like that should work

Func go() ;Search for the color until it find it, then click it and exit loop
    $x = 0
    Do
        $CurrentPos = MouseGetPos()
        $color = pixelgetcolor($CurrentPos[0] , $CurrentPos[1])
        $Coord = PixelSearch(515, 255, 1030, 595, $color)
        If IsArray($Coord) Then
            MouseClick("Left", $Coord[0], $Coord[1], 1, 0)
            $x = 1
        EndIf
        MouseMove($CurrentPos[0], $CurrentPos[1], 0)
    Until $x = 1
EndFunc

If you want it to never stop to run, replace "Do" by "While 1" and "Until $x = 1" by "Wend"

Link to comment
Share on other sites

Try this so you have an easy way to get out of this endless loop in case the color is not found.

HotKeySet("{ESC}", "StopFunction")
Global $x = 0
go()
Func go() ;Search for the color until it find it, then click it and exit loop
    Do
        $CurrentPos = MouseGetPos()
        $color = PixelGetColor($CurrentPos[0], $CurrentPos[1])
        $Coord = PixelSearch(515, 255, 1030, 595, $color)
        If IsArray($Coord) Then
            MouseClick("Left", $Coord[0], $Coord[1], 1, 0)
            ConsoleWrite("yes" & @CRLF)
            Return 1
        EndIf
        MouseMove($CurrentPos[0], $CurrentPos[1], 0)
    Until $x = 1
    ConsoleWrite("no" & @CRLF)
    Return 0
EndFunc   ;==>go

Func StopFunction()
    $x = 1
EndFunc   ;==>StopFunction

Kohr

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...