Sign in to follow this  
Followers 0
daxle

PixelSearch Help

13 posts in this topic

Ok, i am trying to make a simple scriptthat takes a reactiontime test and wins it it. The test is basically when the color changes from red to green you click it as fast as you can.(http://www.humanbenchmark.com/tests/reactiontime/index.php)so i am having it look for green and click it, here is my code.

$s=1
While $s=1
$reaction = PixelSearch("", "", "", "",0x00CC33)
If Not @error Then
    MouseClick( "Left", $reaction[0], $reaction[1])
EndIf   
WEnd

So, if anybody could help i would appreciate it

Share this post


Link to post
Share on other sites



$reaction = PixelSearch("", "", "", "",0x00CC33)
The rectangle coordinates are not optional.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Ok, i am trying to make a simple scriptthat takes a reactiontime test and wins it it. The test is basically when the color changes from red to green you click it as fast as you can.(http://www.humanbenchmark.com/tests/reactiontime/index.php)so i am having it look for green and click it, here is my code.

$s=1
While $s=1
$reaction = PixelSearch("", "", "", "",0x00CC33)
If Not @error Then
    MouseClick( "Left", $reaction[0], $reaction[1])
EndIf   
WEnd

So, if anybody could help i would appreciate it

It would also be much more efficient to use the PixelGetColor() function.

If PixelGetColor(500, 500) = Dec ( 00CC33 ) Then MouseClick(500, 500, 1, 1)

Not 100% positive on the Dec() part, but I think it'd work.

Share this post


Link to post
Share on other sites

It would also be much more efficient to use the PixelGetColor() function.

If PixelGetColor(500, 500) = Dec ( 00CC33 ) Then MouseClick(500, 500, 1, 1)

Not 100% positive on the Dec() part, but I think it'd work.

Thanks for the help, could you please elaborate on where to put that code, maybe use it in my code. Im sorta new at this :), you can probably tell. Thanks alot!

Share this post


Link to post
Share on other sites

The rectangle coordinates are not optional.

Thanks 4 the help, could you elaborate on how to put the coords in. Do I put it in like
$reaction = PixelSearch("x,y", "x,y", "x,y", "x,y",0x00CC33)
Or is there some other way im supposed to do it?

Share this post


Link to post
Share on other sites

This will solve the puzzle (assuming some part of the box appears at 500,500)

While PixelGetColor(500, 500) <> 0x00CC33
sleep(1)
WEnd
MouseClick("left",500, 500, 1, 0)

In this case PixelSearch probably isn't the best because you know where the green will appear, and it's probably quicker to just check the colour in a known location. Pixelsearch has to scan the area which is more CPU intensive.

From the help file:

PixelSearch ( left, top, right, bottom, color [, shade-variation [, step [, hwnd]]] )

Say you want to define the search area where the upper right is (x,y)=(100,200) and extend to (x,y)=(500,600)

You'd do something like:

Pixelsearch(100,200,500,600,0x00CC33)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok, i am trying to make a simple scriptthat takes a reactiontime test and wins it it. The test is basically when the color changes from red to green you click it as fast as you can.(http://www.humanbenchmark.com/tests/reactiontime/index.php)so i am having it look for green and click it, here is my code.

$s=1
While $s=1
$reaction = PixelSearch("", "", "", "",0x00CC33)
If Not @error Then
    MouseClick( "Left", $reaction[0], $reaction[1])
EndIf   
WEnd

So, if anybody could help i would appreciate it

Ok, i have modified the code with major help from TurionAltec, aggixx, and Skruge. Now it will click...once. it refuses to run in a loop. If anyone has suggestions please reply.

Sleep(3000)
MsgBox(0,"Starting", "We are ready to start!")
$s=1
While $s=1
    $reaction = PixelSearch("413,551", "621,477", "849,559", "656,656", 0x00CC33)
    MouseClick("left", $reaction[0], $reaction[1])
WEnd
Edited by daxle

Share this post


Link to post
Share on other sites

Sleep(3000)
MsgBox(0,"Starting", "We are ready to start!")
$s=1
While $s=1
    $reaction = PixelSearch("413,551", "621,477", "849,559", "656,656", 0x00CC33)
    MouseClick("left", $reaction[0], $reaction[1])
WEnd

I have this code, but it will not loop!!! please help me

Share this post


Link to post
Share on other sites

I don't see why your PM was necessary.

It is not looking for 4 coordinate pairs, and it isn't looking for them in quotes.

Did you not see what I wrote?

PixelSearch ( left, top, right, bottom, color [, shade-variation [, step [, hwnd]]] )

Say you want to define the search area where the upper right is (x,y)=(100,200) and extend to (x,y)=(500,600)

You'd do something like:

Pixelsearch(100, 200, 500, 600, 0x00CC33)

That's: Pixelsearch(x1, y1, x2, y2, 0x00CC33)

You're supposed to be defining a rectangle by the upper left and lower right point. I have no idea what shape you're trying to describe.

Share this post


Link to post
Share on other sites

I don't see why your PM was necessary.

It is not looking for 4 coordinate pairs, and it isn't looking for them in quotes.

Did you not see what I wrote?

PixelSearch ( left, top, right, bottom, color [, shade-variation [, step [, hwnd]]] )

Say you want to define the search area where the upper right is (x,y)=(100,200) and extend to (x,y)=(500,600)

You'd do something like:

Pixelsearch(100, 200, 500, 600, 0x00CC33)

That's: Pixelsearch(x1, y1, x2, y2, 0x00CC33)

You're supposed to be defining a rectangle by the upper left and lower right point. I have no idea what shape you're trying to describe.

Thank you, you have helped me to complete it(yes, i have finally done it) and now it works perfectly, thankyou

Share this post


Link to post
Share on other sites

Is there any way for me to have it search for every shade of a color, so that if the angle or lighting changes it will still click it?

Share this post


Link to post
Share on other sites

by angle or lighting I assume you mean in a game, since the page you linked won't have any impact on the lighting in the room, or the viewing angle.

look at the shade-variation option

from the help file:

[optional] A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the colour. Default is 0 (exact match).

Share this post


Link to post
Share on other sites

Sorry but I had to do this:

HotKeySet("{ESC}", "_Exit")
HotKeySet("{HOME}", "Start")

While 1
    Sleep(100)
WEnd


Func Start()
While 1
$mPos = MouseGetPos()
$Bot = PixelSearch($mPos[0], $mPos[1], $mPos[0] + 10, $mPos[1] + 10, 0x00CC33, 5)
If Not @error Then
    MouseClick("Left")
    Sleep(100)
    MouseClick("Left")
EndIf
WEnd
EndFunc     ;Start


Func _Exit()
    Exit
EndFunc     ;Exit

All you do is put your mouse over the box push home click once let it go.

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