Sign in to follow this  
Followers 0

Function does not always work

1 post in this topic

#1 ·  Posted (edited)

I wanted a function to scan the screen, but a PixelSearch() generates "false positives" and a PixelChecksum() in a loop takes too long.

So I made a function to PixelSearch for the color, then do a PixelChecksum() there, and continue searching from that point on if needed.

However, sometimes it does not work.

If I tell it to find the "Profile Editor" or "TrackMania Nations" icon on my desktop, it finds them where ever I put them. But it does not find the "Total Annihilation" or an Auto-It script Icon.

I've made a test-script for the function.

Press shift-home to get the pixelcolor of a random pixel and the checksum around it, and then call the ItemCheck() function with that info.

So basically it gets a pixelcolor and checksum from the screen and then searches for it. But it still does not always work.

(Use a picture with a lot of colors as your desktop-background, otherwise it may search for a loooong time)

(put a comment sign in front of the mousemove in line 37 if you dont want to mousecurser to move while searching)

HotKeySet("+{END}", "Terminate")

Dim $TermProg=0
Dim $FoundIt=0
Dim $pos[2],$oldpos[2]


While Not $TermProg

Func ItemCheck($PColor,$PChkSum,$DifX,$DifY)                                    ; color of pixel to find, pixelchecksum, width, heigth
    $FoundIt=0                                                                  ; havent found it yet
    $xsta=0                                                                     ; start searching upper left corner
    $xend=1279-$DifX                                                            ; end searchin lower right
    $xcur=$xsta                                                                 ; got an error if they aren't declared
    $Coords=PixelSearch($xsta,$ysta,$xend,$yend,$PColor)                        ; search for a pixel with the wanted color
    While NOT @Error And Not $FoundIt
        $ycur=$Coords[1]                                                        ; coordinates
        ToolTip("Found the right color"&@CR&$xcur&","&$ycur,100,100)
        MouseMove($xcur,$ycur,0)                                                ; move mouse there, just to indicate where we are searching
;       Sleep(100)
        $PixChkSum=PixelChecksum($xcur,$ycur,$xcur+$DifX,$ycur+$DifY)           ; do a pixelchecksum at the location we just found
        If $PixChkSum>=$PChkSum-10 And $PixChkSum<=$PChkSum+10 Then             ; compare to what we want to find
;           MouseMove($xcur,$ycur,0)                                            ; if we found it. (pixelcolor and checksum)
;           ToolTip("     Found it     ")
;           Sleep(2500)
        Else                                                                    ; right color, but wrong checksum
;           ToolTip("Checksum klopt niet")
;           Sleep(1000)
            $Coords=PixelSearch($xcur,$ycur+1,$xcur,$yend,$PColor)              ; search from 1 pixel below current location to the end of the column
            If @Error Then                                                      ; if we haven't found it there
                $Coords=PixelSearch($xcur+1,$ysta,$xend,$yend,$PColor)          ; search from the top of the next column to the bottom-right corner
    WEnd                                                                        ; loop
    If $FoundIt Then
        ToolTip("     Found it     ")
        ToolTip("     We did not find anything     ")

Func TT4()
    $Randx=Random(0,1229,1)                                                     ; get a random position
    $PixToFind=PixelGetColor($Randx,$Randy)                                     ; get the color of the random position
    $PixChkSumToFind=PixelChecksum($Randx,$Randy,$Randx+50,$Randy+20)           ; calc pixelchecsum of that area
    ToolTip($PixToFind & "  " & $PixChkSumToFind)                               ; move there and show what we found in a tooltip
    ItemCheck($PixToFind,$PixChkSumToFind,50,20)                                ; use that data in the other function

Func Terminate()
    $TermProg=1                                                                 ; terminate program.  I do not like the use of while 1..... wend loops
Edited by JayJay

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