Sign in to follow this  
Followers 0
Airwolf

Find Pixelchecksum

2 posts in this topic

#1 ·  Posted (edited)

This is my first UDF, so please don't be too harsh. :rolleyes: It was inspired by a game; I wanted to move icons around on screen but they all had the same colors within them so I couldn't use a simple PixelSearch. Hopefully nothing already exists like this because I spent quite a bit of time on what seems to be a simple script. :rambo: I got the idea for the design from a few posts about attempting to find checksums here on the forums.

Here is the header of the script file explaining how the function is setup and how to pass parameters to it. If you have any suggestions for adding other functions or making this one better, I'm all ears! I am probably going to modify it soon to allow for array input to find multiple checksums.

; ===================================================================================

#cs

Syntax is as follows: _findchecksum($checksum, $width, $height, $pcolor, $x = 0, $y = 0, $d_width = @DesktopWidth, $d_height = @DesktopHeight)

$checksum - the checksum to search for

$width - the width of the checksum area

$height - the height of the checksum area

$pcolor - the pixel color of the top left pixel of the checksum object

$x - the starting x coordinate

$y - the starting y coordinate

$D_Width - Width of the total search area, default is desktop resolution width

$D_Height - Height of the total search area, default is desktop resolution height

The function returns the x and y coordinates of the upper left corner where the checksum

is found as an array. For Example:

$coordinates = _findchecksum($checksum, $width, $height, $pcolor)

The x coordinate would be $coordinates[0] and the y coordinate would be $coordinates[1].

If the coordinates are not found, the function will return a value of 0.

#ce

; ===================================================================================

And here is an example script I created to calculate the checksum of an area and then find that checksum using hotkeys.

#include <findchecksum_UDF.au3>

Global $checksum, $coord, $pcolor

; Specify checksum width
Global $width = 30
; Specify checksum height
Global $height = 30

HotKeySet("{ENTER}","checksum_record")

Global $instructions1 = "Move the mouse to the top left of the search" & @LF & "area and then press Enter to record the area."
Global $instructions2 = "Press the F key to find the recorded area."

While $checksum = ""
    $coord = MouseGetPos()
    $pcolor = PixelGetColor($coord[0], $coord[1])
    ToolTip($instructions1 & @LF & @LF & "x = " & $coord[0] & @LF & "y = " & $coord[1] & @LF & @LF & "Decimal Pixel Color = " & $pcolor, $coord[0] - 250, $coord[1] - 100)
    Sleep(100)
WEnd

HotKeySet("f","checksum_find")

While 1
    ToolTip($instructions2)
    Sleep(100)
WEnd

Func checksum_record()
    $checksum = PixelChecksum($coord[0], $coord[1], $coord[0] + $width, $coord[1] + $height)
    HotKeySet("{ENTER}")
EndFunc

Func checksum_find()
    ToolTip("")
    $found = _findchecksum($checksum, $width, $height, $pcolor)
    If $found = 0 Then
        MsgBox(4096,"Error","Checksum not found.")
        Exit
    Else
        MouseMove($found[0] + ($width / 2), $found[1] + ($height / 2), 1000)
        ToolTip("Found it!")
        Sleep(5000)
        ToolTip("")
        MsgBox(0,"Checksum Found","Checksum found with center at x=" & $found[0] + ($width / 2) & " y=" & $found[1] + ($height / 2) & ".")
        Exit
    EndIf
EndFunc

findchecksum_UDF.au3

findchecksum_example.au3

Edited by Airwolf123

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites



This is great! I have used it to replace a bunch of spagetti code I had doing the same thing.

The only problem is that it can be very slow if there is a lot of pixels matching the color you are searhing for.

Is there any way to speed this up at all that you can think of?

Thanks again for your time and efforts!

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