Jump to content

Find/Move Mouse To Color


Jasio
 Share

Recommended Posts

  • Moderators

Pixelgetcolor/PixelSearch in the helpfile.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

$Blah = PixelGetColor(0, 100)

MsgBox(0, 'Test', '0x' & Hex($Blah, 6))

Edit: Be sure your using the Correct PixelCoordMode depending on the type of coordinates your collecting. Check out Opt('PixelCoordMode', #) in the help.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Look at my edit:

Edit:

I typically use client coords, so I'll show you an example (to use client coords in the autoinfo tool, go to options / coord mode)

Opt('PixelCoordMode', 2)
$Blah = PixelGetColor(100, 100)
MsgBox(0, 'Test', '0x' & Hex($Blah, 6))

P.S., the color at that time at those coordinates could have been black is why you were getting 0x000000

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Hmmm, as usual I mis-understood your post... To get the color under the mouse there are 5 things you'll want to look at in detail:

1. PixelCoordMode

2. MouseCoordMode

3. _IsPressed() A UDF that is in the Misc.au3 file of the Beta Version of Autoit (See my signature)

4. MouseGetPos

5. PixelGetColor

So an example would be: (I'll include the UDF to help you a bit)

Opt('PixelCoordMode', 2)
Opt('MouseCoordMode', 2)

While 1
    If _IsPressed('01') Then; '01' identifies the left mouse button
        Local $Pos = MouseGetPos()
        $PixColor = PixelGetColor($Pos[0], $Pos[1])
        ToolTip('The Colour is: 0x' & Hex($PixColor, 6))
    EndIf
    Sleep(10)
WEnd

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc

Edit: For Search You'll use PixelSearch()

Opt('PixelCoordMode', 2)
Opt('MouseCoordMode', 2)

Local $xTopLeft = 0; starting point
Local $yTopLeft = 0; starting point
Local $xBottomRight = 200 
Local $yBottomRight = 200
Local $ColorToFind = 0xFF0000

While 1
    Local $PixSearch = PixelSearch($xTopLeft, $yTopLeft, $xBottomRight, $yBottomRight, $ColorToFind)
    If Not @error And IsArray($PixSearch) Then MouseClick('Left', $PixSearch[0], $PixSearch[1], 1, 1)
    Sleep(100)
WEnd
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm sorry for the miscommunication, i can't seem to word them better.. This script is for a game, i would like it to find a specific color (which is basically a red/orange circle in a large grey area.. then click on it

a problem im having is, when i get the hex color, E0DFE3, i put it in the PixelSearch, it then gives me coords 0, 48.. The object in which i want it to locate is in the middle of the screen and no where near the top left.

I hope this clears up more of this than it complicates

Thanks,

Jasio

Link to comment
Share on other sites

  • Moderators

I edited the above post to show you how already :lmao:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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