Sign in to follow this  
Followers 0
tigolbitties

Pixelsearch not working

8 posts in this topic

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

Share this post


Link to post
Share on other sites



MouseClick("left", $coords[0], $coords[1], 1) ;runescape

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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

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  
Followers 0