Jump to content

pixelsearch


Recommended Posts

I need help making a script to pixelsearch for a certain color, and then move the mouse to that color and right click it.. Willing to pay with paypal, msn: izorins@gmail.com

what i have seen from people is:

Func _ScanOverheadMap()

If $winpos[2] = 646 Then

;windowed

$coord = PixelSearch($winpos[0] + 3 + 50, $winpos[1] + 22 + 25, $winpos[0] + 3 + 580, $winpos[1] + 22 + 270, 0x7BA6F7, 0, 5)

Else

;fullscreen

$coord = PixelSearch($winpos[0] + 50, $winpos[1] + 25, $winpos[0] + 580, $winpos[1] + 270, 0x7BA6F7, 0, 5)

EndIf

If IsArray($coord) Then

Return True

Else

Return False

EndIf

Link to comment
Share on other sites

Welcome to the forums!

This should do it:

; Search the entire desktop for colour #7BA6F7
Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, 0x7BA6F7)
; If successful then click that location
If Not @Error Then MouseClick('Right', $Coords[0], $Coords[1])

Edit: Changed to the colour from the top post.

Edited by LxP
Link to comment
Share on other sites

  • Moderators

Look at Opt("PixelCoordMode", NUMBER) in the help file, if you are wanting to do it in a specific window, you'll need to replace 'NUMBER' with either 2 or 0, and make sure the Coordinates your using are using the same (Client or Window Coords) using the AutoInfo tool (Can be changed in Options on the AutoInfo tool).

Also look at Opt("MouseCoordMode", NUMBER) using the same example to replace 'NUMBER'.

Then it should work on your game.

So my code would look something like:

Opt("WinTitleMatchMode", 4)
Opt("PixelCoordMode", 2)
Opt("MouseCoordMode", 2)

Global $GameTitle = "My Game"

While 1
    If Not WinActive($GameTitle) Then WinActivate($GameTitle)
    $Coords = PixelSearch(xCoordStart, yCoordStart, xCoordEnd, yCoordEnd, 0x7BA6F7)
    If Not @Error And IsArray($Coords) Then MouseClick('Left', $Coords[0], $Coords[1], 1, 1)
    Sleep(10)
Wend

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

maybe because it doesnt repeat?

Precisely.

Ron's code will repeat and it will also continually click the same spot. Is that desired or should the code wait until the spot that was clicked change colour?

Edit: Added context.

Edited by LxP
Link to comment
Share on other sites

Something like this will do it then:

; Define colour to match
Local $Match = 0x7BA6F7

; Loop indefinitely
While 1
; Search the entire desktop for colour
    Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)
; If successful then click that location
    If Not @Error Then
        MouseClick('Right', $Coords[0], $Coords[1])
    ; Wait until the colour at that point changes
        Do
            Sleep(100)
        Until PixelGetColor($Coords[0], $Coords[1]) <> $Match
    Else
        Sleep(100)
    EndIf
WEnd

Ron's example will help you if you're looking to adapt the code to work with a windowed game as well.

Another piece of advice: grab the beta and set that up as the default to run scripts (Start > Programs > AutoIt v3 > Beta > Toggle AU3 Beta) because it has an improved PixelSearch() engine which will give much faster results.

Link to comment
Share on other sites

Something like this will do it then:

; Define colour to match
Local $Match = 0x7BA6F7

; Loop indefinitely
While 1
; Search the entire desktop for colour
    Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)
; If successful then click that location
    If Not @Error Then
        MouseClick('Right', $Coords[0], $Coords[1])
; Wait until the colour at that point changes
        Do
            Sleep(100)
        Until PixelGetColor($Coords[0], $Coords[1]) <> $Match
    Else
        Sleep(100)
    EndIf
WEnd

Ron's example will help you if you're looking to adapt the code to work with a windowed game as well.

Another piece of advice: grab the beta and set that up as the default to run scripts (Start > Programs > AutoIt v3 > Beta > Toggle AU3 Beta) because it has an improved PixelSearch() engine which will give much faster results.

ok did that, but it doesnt work ingame but on my desktop it does.
Link to comment
Share on other sites

  • Moderators

Use the options that are in mine (Opt()'s) with Alex's code as he stated.

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

Opt("WinTitleMatchMode", 4)

Opt("PixelCoordMode", 2)

Opt("MouseCoordMode", 2)

; Define colour to match

Local $Match = 0xEF6B08

; Loop indefinitely

While 1

; Search the entire desktop for colour

Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)

; If successful then click that location

If Not @Error Then

MouseClick('Right', $Coords[0], $Coords[1])

; Wait until the colour at that point changes

Do

Sleep(100)

Until PixelGetColor($Coords[0], $Coords[1]) <> $Match

Else

Sleep(100)

EndIf

WEnd

like that?

Link to comment
Share on other sites

When you say 'it doesn't work', what exactly do you mean? Does the mouse move in any way? Does it click the wrong location?

I would suggest trying this script with the beta; it will beep high to indicate that it found the pixel or low otherwise. I've also slowed it down so that the beeps don't drive you mad.

; Define colour to match
Local $Match = 0xEF6B08

; Loop indefinitely
While 1
; Search the entire desktop for colour
    Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)
; If successful then click that location
    If Not @Error Then
        Beep(800, 50)
        MouseClick('Right', $Coords[0], $Coords[1])
; Wait until the colour at that point changes
        Do
            Sleep(1000)
        Until PixelGetColor($Coords[0], $Coords[1]) <> $Match
    Else
        Beep(100, 50)
        Sleep(1000)
    EndIf
WEnd
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...