Jump to content

Resuming a PixelSearch


Keltset
 Share

Recommended Posts

First off, Hello all...

I have spent about 9 hours now trying to figure out how to use PixelSearch and the PixelChecksum to do what I want. I have been using AutoIt for awhile to do -very basic move mouse click- type macros to simplify my life. I decided I'd like to learn more with it. Here is what I am trying to do.

I have a specific color that I created a 10 x 10 checksum around (which I want to use to validate the result from PixelSearch to ensure it gets the right color in the right location not the right color in the wrong location)

So the problem I have run into is that I now have saved the proper checksum for what I'm trying to find, and I know the color hex so I start my search:

($testColor is the hex color, $testSum is the checksum we want to match to)

Func test()
    $PixSearch = PixelSearch(368, 398, 1107, 740, $testColor, 3)
    While 1
    If Not @error And IsArray($PixSearch) then
        MsgBox(0,"Pixel Match", "we got a match lets pull checksum")
        sleep(1000)
        $checksum = PixelGetColor( $PixSearch[0] , $PixSearch[1] )
        MsgBox(0,$testSum, $checksum)
        If $checksum = $testSum Then
            Sleep(1)
            MouseClick('Left', $PixSearch[0], $PixSearch[1], 1, 25)
            Exit
        EndIf
    EndIf
    WEnd
EndFunc

I have messed with that code alot so it may not be exactly right but gives you the idea what I am doing. The problem is first Pixel match is not the right checksum so I want to make it continue the search until I get a match on BOTH the color hex and the checksum.

This cannot possibly be that complicated and I'm sure is easy to do but after 9+ hours of trying to figure this out and reading forum posts I decided to register and post my question and hopefully someone out there can take pity on me and give me a hand with this pesky little issue...

Thanks,

Keltset

-K

Link to comment
Share on other sites

I have tried saving the X / Y to variables then running a new pixel search starting one pixel to the right and finishing of that row (I think Pixel search goes top down / left right) then start it again the first pixel of the next row. The problem now seems to be the massive amount of time this is taking... I have yet to get it to match my checksum due to allowing it to run for 5 minutes and then canceling (if its going to take 5mins to work its not going to do what I need it to...) uhg

-K

Link to comment
Share on other sites

I have no idea what I posted last night with that messed up code... I must have been tired. Here is what I am doing today and its mostly working, I am sure there are better ways but its all I can figure out how to do it.

Func AutoClickByColor($clr, $csm)
    Local $PixSearch, $checksum, $top, $bottom, $left, $right
    $left = 373
    $top = 377
    $right = 1107
    $bottom = 740
    $PixSearch = PixelSearch($left, $top, $right, $bottom, $clr)
    While $top < $bottom
        $PixSearch = PixelSearch($left, $top, $right, $bottom, $clr)
        If Not @error And IsArray($PixSearch) Then
            ;MsgBox(0,"Pixel Match", "we got a match lets pull checksum")
            ;sleep(1000)
            $checksum = PixelChecksum($PixSearch[0] - 2, $PixSearch[1] - 2, $PixSearch[0] + 2, $PixSearch[1] + 2)
            ;MsgBox(0,$csm, $checksum, 1)
            If $checksum = $csm Then
                ;MsgBox(0,"WOW", "OMG THIS IS WHERE WE WANT TO BE")
                Sleep(250)
                MouseClick('Left', $PixSearch[0], $PixSearch[1], 1, 25)
            EndIf
        EndIf
        $top = $top + 1
    WEnd

    Local $PixSearch, $checksum, $top, $bottom, $left, $right
    $left = 373
    $top = 377
    $right = 1107
    $bottom = 740
        $PixSearch = PixelSearch($left, $top, $right, $bottom, $clr)
    While $left < $right
        $PixSearch = PixelSearch($left, $top, $right, $bottom, $clr)
        If Not @error And IsArray($PixSearch) Then
            ;MsgBox(0,"Pixel Match", "we got a match lets pull checksum")
            ;sleep(1000)
            $checksum = PixelChecksum($PixSearch[0] - 2, $PixSearch[1] - 2, $PixSearch[0] + 2, $PixSearch[1] + 2)
            ;MsgBox(0,$csm, $checksum, 1)
            If $checksum = $csm Then
                ;MsgBox(0,"WOW", "OMG THIS IS WHERE WE WANT TO BE")
                Sleep(250)
                MouseClick('Left', $PixSearch[0], $PixSearch[1], 1, 25)
            EndIf
        EndIf
        $left = $left + 1
    WEnd
    ;Exit
EndFunc   ;==>AutoClickByColor

I am now passing it the color HEX and the pixel area checksum with $clr, $csm

Edited by Keltset

-K

Link to comment
Share on other sites

Figured I would post what I changed it to its a little less code and seems to be working fairly well, again I bet there are betters ways but its what I've done, hope this helps someone else out there

Note on this: you must pass in the color and checksum to this function that you are matching

Func ClickByColor($clr, $csm)
    Local $PixSearch, $checksum, $top, $bottom, $left, $right
    $left = 373
    $top = 377
    $right = 1107
    $bottom = 740
    $PixSearch = PixelSearch($left, $top, $right, $bottom, $clr)
    While $top < $bottom
        If WinActive("My Window") Then
            $PixSearch = PixelSearch($left, $top, $right, $bottom, $clr)
            If Not @error And IsArray($PixSearch) Then
                $checksum = PixelChecksum($PixSearch[0] - 2, $PixSearch[1] - 2, $PixSearch[0] + 2, $PixSearch[1] + 2)
                If $checksum = $csm Then
                Sleep(100)
                          MouseClick('Left', $PixSearch[0], $PixSearch[1], 1, 10)
                EndIf
            EndIf
            If $top > $bottom Then
                $left = $left + 1
            Else
                $left = 373
                $top = $top + 1
            EndIf
        EndIf
    WEnd
EndFunc

To get the checksum and the color code I am using this little script I wrote:

$x = 717
$y = 386

$xycheck = PixelChecksum($x - 2, $y - 2 , $x + 2, $y + 2)
$current = PixelGetColor( $x , $y )

ClipPut(Hex($current, 6))
MsgBox(0, Hex($current, 6), "Color Hex for specified pixel copied to clipboard!")

ClipPut($xycheck)
MsgBox(0, $xycheck, "CheckSum for specified pixel copied to clipboard!")

Just change the x / y to the pixel you want to get a color code and make a checksum for, keep in mind the checksum is created from a couple pixels around the x/y you specify. This color code and checksum can be passed into the other function I posted and works perfectly. Keep in mind though that the color code you get from this looks something like FFFFFF, its missing the "0x", you must get that 0x attached before passing the color to the pixelsearching function. (meaning color hex must look like 0xFFFFFF not FFFFFF)

Hope this helps someone not bang their head for 2-3 days like I did on this...

Keltset

-K

Link to comment
Share on other sites

I stumbled upon a thread in this forum that resolves the issues I've been having in a much MUCH better way...

http://www.autoitscript.com/forum/index.php?showtopic=95623&st=0&p=734992&hl=find%20pixel%20pattern&fromsearch=1&#entry734992

-K

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