Jump to content
Sign in to follow this  
Drew

How do you get the mouse to search for a pixel color?

Recommended Posts

Drew

I don't understand how to make the cursor search for a certain given color and click it.

**Also , once I do figure that first part out, what if there are 2 of the exact same color , how will it know which to pick?

EDIT

and while im at it on asking stupid questions , (i already tried looking in the help dept. so please don't shoo me off there.)

How would i make a message window that I created , stay on top...

and whats the func. to start with a hotkey...

Edited by Drew

Share this post


Link to post
Share on other sites
thetwistedpanda

Opt("PixelCoordMode", 2)
#include <GUIConstants.au3>

GUICreate("Pixel Search", 200, 200, Default, Default)
GUICtrlCreateIcon(@ProgramFilesDir & "\AutoIt3\Icons\au3.ico", -1, 76, 64, 48, 48)
GUISetState()

$Pixel = PixelSearch(25, 25, 150, 150, "0x6097D1", 5, 1)

If Not @Error Then
    MsgBox(4096, "Pixel Results", "X: " & $Pixel[0] & ", Y: " & $Pixel[1])
EndIf

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
WEnd

GUIDelete()
Exit

I'll give this one a shot. The help file basically states that in order for PixelSearch to work, you need a rectangle (i.e, 4 separate points). A left point, a high point, a right point, and a low point, making a rectangle if there were lines drawn.

I don't know if the above example will work, but it should. PixelSearch is going to search inside of the rectangle I provided for a certain color, say "0x6097D1". There's a 'shade variation' of 5, which means it's not going to be exact, but it's going to be very close.

From the help file: "The search is performed left-to-right, top-to-bottom and the first match is returned." - this should answer the question concerning multiple colors. Once it finds the appropriate color (or shade variant), it returns a two-element array of the pixel's coordinates (In this case, $Pixel[0] and $Pixel[1]).

Now that the coordinates are found, making it click is relatively easy: MouseClick("left", $Pixel[0], $Pixel[1], 1, 10) for example. It would be wise to include this line of code inside of the If Not @Error Then statement, as if the color is not found, this will produce a lovely error.

*Edit* - I seem to have skipped a question haha. If you mean message window as in MsgBox(), I have no idea, but for a gui, you could try $WS_EX_TOPMOST in the Gui's extended style section thing *End Edit*

And to answer your final question, I believe you're looking for HotKeySet ( "key" [, "function"] )

Hope this helps - If not, I'm sure more experienced members will be along within the next four to eight hours to help ya out.

Edited by thetwistedpanda

Share this post


Link to post
Share on other sites
Drew

No , your doing just fine. lol , im somewhat understanding this ( but im new so yeah ).

Couple questions, Whered did you come up with "certain color, say "0x6097D1"". Or how did you come up with that color i mean. I think I understand on pixel coordinates for a particular rect. for it to search it. That sounds simple. I just don't know how to get the ###'s for a color.

Share this post


Link to post
Share on other sites
Drew

WOW ... I think i answered my own question this time. AutoIt Window Info works WONDERS lol. I love autoit :)

Share this post


Link to post
Share on other sites
thetwistedpanda

WOW ... I think i answered my own question this time. AutoIt Window Info works WONDERS lol. I love autoit :)

Haha Yep, that's what I used.

Share this post


Link to post
Share on other sites
Drew

alright that didn't take long.. back for help. In your example it has these for the 4 rect. points ( 25, 25, 150, 150 )

I thought a mouse point had two coordinates ( x, y ) so that would take 2 numbers eg: 5,731

I don't understand how one number represents a position on the screen >< I have to be missing something unless you only need one coordinate ( x or y ) for one corner. I'm in a state of confusion atm , please help ><

EDIT

whats STEP , on the last part of all that

[, step]] )

Edited by Drew

Share this post


Link to post
Share on other sites
Drew

Heres the code I have so far.

CODE
Opt("MouseClickDragDelay", 5000)

Opt("PixelCoordMode", 2)

#include <GUIConstants.au3>

GUICreate("Pixel Search", 200, 200, Default, Default)

GUICtrlCreateIcon(@ProgramFilesDir & "\AutoIt3\Icons\au3.ico", -1, 76, 64, 48, 48)

GUISetState()

PixelSearch ( 5, 138, 796, 615, 0x745028 [, 5] [, 1]] )

If Not @Error Then

MsgBox(4096, "Pixel Results", "X: " & $Pixel[0] & ", Y: " & $Pixel[1])

EndIf

While 1

$msg = GUIGetMsg()

Switch $msg

Case $GUI_EVENT_CLOSE

ExitLoop

EndSwitch

WEnd

GUIDelete()

Exit

I copied and pasted and filled in what I thought I needed to. Here are the coordinates of the window I want it to search in:

Top Left: 5,138

Top Right: 796, 141

Bottom left: 19, 615

Bottom Right: 793, 628

So I don't know If I used the right coordinates in my codeing , I guessed on whether to use X , or Y at each left, right, top, bottom point. This is the Error I recieved:

PixelSearch ( 5, 138, 796, 615, 0x745028 [, 5] [, 1]] )

PixelSearch ( 5, 138, 796, 615, 0x745028^ERROR

or something like that. I'm confused once again :). I don't understand where I went wrong.

Share this post


Link to post
Share on other sites
Drew

i still badly need help with this ><

Share this post


Link to post
Share on other sites
Jos

@Drew,

You would help yourself tremendiously when you first try to learn to walk before starting to run .....

Learn about proper AutoIt3 syntax first ..

:)


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Drew

Well i just typed Autoit3 Syntax into the help search and it didn't give me anything about it.

Can ya just try and explain what i need to know lol. I learn by practice.

Share this post


Link to post
Share on other sites
Jos

Well i just typed Autoit3 Syntax into the help search and it didn't give me anything about it.

Can ya just try and explain what i need to know lol. I learn by practice.

start here

:)


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Drew

NOOOOOOOOOOOOOOOO

i tried that already. couldn't even get past the basic exam.

Share this post


Link to post
Share on other sites
Drew

okay i tried that again... the voice is shit and i can't understand any of it... therefor useless to me.

I still need help :)

Share this post


Link to post
Share on other sites
Jos

NOOOOOOOOOOOOOOOO

i tried that already. couldn't even get past the basic exam.

Now what did that tell you ? :)

okay i tried that again... the voice is shit and i can't understand any of it... therefor useless to me.

I still need help :)

Goto Start:


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  

×