Jump to content

Pixelsearch not working


Recommended Posts

I'm trying to write a simple program click on specific colors on my active window. When I use pixelsearch all that happens is the mouse goes to the top left of my screen and clicks. please help, I have already browsed the forums and several other webpages but cannot find a simple solution.

post-65262-0-10230700-1307233930_thumb.j

Here's my simple code:

$i = 0

While $i < 5 ; number of clicks until script stops

$coords = pixelsearch (544, 419, 716, 436, 0xCCB63A, 10, 0)

if not @error then

MouseClick("left", $coords, $coords, 1)

endif

$i = $i + 1

WEnd

Link to comment
Share on other sites

Thank you for your help, but can you please explain what that [0] and [1] actually mean? x=0 and y=1 ?

Check out the AutoIt help file on the PixelSearch function. There you'll see that if successful, it returns an array that here is being placed into the $coords variable. The x location is placed in the 0 item in the array and the y location in the 1 item in the array (which is actually the second item in the array since arrays are 0 based). You might want to test this out by printing out $coord[0] and $coord[1] to the console inside of your if block by using the ConsoleWrite function.

What is the goal of your little application by the way?

Link to comment
Share on other sites

I'd add 1 to $i within the if statement, because even if PixelSearch doesn't find it, it will still add 1 to $i during the cycle, like this:

$i = 0
While $i < 5
$coords = pixelsearch (544, 419, 716, 436, 0xCCB63A, 10, 0)
if not @error then MouseClick("left", $coords, $coords, 1)
$i = $i + 1
endif
WEnd

With this above the while statement will end in millisecondes if you dont get a syntax error first.

Correct Usage:

$i = 0
While $i < 5
    $coords = PixelSearch(544, 419, 716, 436, 0xCCB63A, 10, 0)
    If Not @error Then
        MouseClick("left", $coords[0], $coords[1], 1)
        $i = $i + 1
    EndIf
WEnd
Edited by rogue5099
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...