Jump to content

Recommended Posts

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")
HotKeySet("+{HOME}","TT4")

Dim $TermProg=0
Dim $FoundIt=0
Dim $pos[2],$oldpos[2]
$pix=0
$PixChkSum=0
$PixToFind=0
$PixChkSumToFind=0
$oldpos[0]=0
$oldpos[1]=0
$pos[0]=0
$pos[1]=0

$Randx=Random(242,961,1)
$Randy=Random(217,796,1)


While Not $TermProg
    Sleep(100)
WEnd

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
    $ysta=0
    $xend=1279-$DifX                                                            ; end searchin lower right
    $yend=1023-$DifY
    $xcur=$xsta                                                                 ; got an error if they aren't declared
    $ycur=$ysta
    $Coords=PixelSearch($xsta,$ysta,$xend,$yend,$PColor)                        ; search for a pixel with the wanted color
    While NOT @Error And Not $FoundIt
        $xcur=$Coords[0]
        $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)
            $FoundIt=1
        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
            EndIf
        EndIf
    WEnd                                                                        ; loop
    If $FoundIt Then
        MouseMove($xcur,$ycur,5)
        ToolTip("     Found it     ")
        sleep(1000)
    Else
        ToolTip("     We did not find anything     ")
    EndIf
EndFunc

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

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...