Sign in to follow this  
Followers 0
GodandRock

find middle coordinate for pixelchecksum

12 posts in this topic

hello all...is there a way in which i can find the MIDDLE coordinates for the rectangle i provide the pixelchecksum for??? like i have a little button on the screen...and i do pixelchecksum on it...and can i make a script that searches for a provided pixelchecksum amount and click in the middle of that rectangle once it finds that the pixelchecksum matches....i realize that this would use a lot of cpu because it will search ALOT...but u can provide sum extra information like how big the rectangle is, and where it is likely to be....help please, if u dont understand, tell me which part and ill explain more....

thank you


[font="Fixedsys"][size="3"][u][font="Franklin Gothic Medium"] [/font][/u][/size][/font]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If I understand correctly, you want something like this:

Local $Left = 20
Local $Top = 20
Local $Right = 100
Local $Bottom = 100

If PixelChecksum($Left, $Top, $Right, $Bottom) = [Checksum] Then
    MouseClick('', ($Left + $Right) / 2, ($Top + $Bottom) / 2)
EndIf

Edit: I believe I'm mistaken. Sorry about that.

I think that you could achieve what you want using a PixelSearch() or two, followed by some specially crafted PixelGetColor() calls. The idea would be to first find (for instance) the top-left pixel of the area that you want to find -- perhaps this pixel is even unique to the entire screen already. If it isn't, you'd need to check some other pixels obviously.

Edited by LxP

Share this post


Link to post
Share on other sites

I wrote this exact thing... I get a pixel color under the mouse and a pixelchecksum of pixels +5 -5 in all directions... giving me an 11x11 square... I pixelsearch for the center pixel then check the rectangle -5 +5 in all directions... if no match, I pixelsearch the rest of that Y coordinate for my pixel, then start pixelsearch from the next Y at X=0. This is the trick... I do this all the way down the screen...

remember pixelsearch whole screen... when you get a hit, check then pixelsearch the rest of that line then pixelsearch at next 0,Y through the rest of the screen... do this until pixelsearch fails or pixelchecksum succeeds...

Lar.

larry, once i search for that center pixel, wat if there r other pixels with the same color?? pixel search might just get another pixel...and wen it fails to match, how will i tell it to skip that pixel and find another pixel with the same color....

thank you


[font="Fixedsys"][size="3"][u][font="Franklin Gothic Medium"] [/font][/u][/size][/font]

Share this post


Link to post
Share on other sites

man im sorry, i dont get it...plus u messed up on the line

"$xy = PixelSearch($x,$y,@desktopwidth - 1,$ypixel)" i think its supposed to be

"$xy = PixelSearch($x,$y,@desktopwidth - 1,$ypixel, $pcolor)"

and wen i get the pixel of the center, am i supposed to find the pixelchecksum of +5 pixels around that center pixel?? or can i get the pixelchecksum of a BIGGER or smaller box around that center???


[font="Fixedsys"][size="3"][u][font="Franklin Gothic Medium"] [/font][/u][/size][/font]

Share this post


Link to post
Share on other sites

the center pixel coordinate, does it have to be PERFECTLY in the center?? and i can use a BIG rectangle too rite??? like maybe 23X23(just an example)


[font="Fixedsys"][size="3"][u][font="Franklin Gothic Medium"] [/font][/u][/size][/font]

Share this post


Link to post
Share on other sites

ok larry, i almost got u, or maybe i already completely got u....for an example can u PLEASE make a script that searches for ur avatar's face....let the left eye be the pixel color, and the rectangle should be the face only...make me that so i can see how u really do it...im really sorry for being such a noob and wasting ur time


[font="Fixedsys"][size="3"][u][font="Franklin Gothic Medium"] [/font][/u][/size][/font]

Share this post


Link to post
Share on other sites

Larry I found your script very useful so I made some additions to it.

#include <GUIConstants.au3>
Global $msg = "Move the mouse to a pixel" & @LF & _
        "that is unique as possible." & @LF & _
        "I will record the area around" & @LF & _
        "into PixelSearch.ini. Press" & @LF & _
        "CTRL + ` (Tilda key) to record."
Global $xy,$pixel

HotKeySet("{ESC}", "Stop")
HotKeySet("^`","record")

While 1
    $xy = MouseGetPos()
    $ColorDec = PixelGetColor($xy[0],$xy[1])
    $ColorHex = Hex($ColorDec, 6)
    $position = ("X=" & $xy[0] & "  " & "Y=" & $xy[1])
    ToolTip("Pixel Position = " & $position & @LF & "Pixel Color Hex = " & $ColorHex & @LF & "Pixel Color Dec = " & $ColorDec & @LF & @LF & $msg)
    Sleep(100)
WEnd

Func record()
    IniWrite(".\PixelSearch.ini","Main","PixelColorHex",$ColorHex)
    IniWrite(".\PixelSearch.ini","Main","PixelColorDec",$ColorDec)
    IniWrite(".\PixelSearch.ini","Main","PixelPosition",$position)
    Local $chksum = PixelChecksum($xy[0] - 5,$xy[1] - 5,$xy[0] + 5,$xy[1] + 5)
    IniWrite(".\PixelSearch.ini","Main","PixelCheckSum",$chksum)
    $answer = MsgBox(4100,"","Pixel Area Recorded." & @LF & @LF & "Your Position Was " & $position & @LF & "Your Hex Color Was " & $ColorHex & @LF & "Your Dec Color Was " & $ColorDec & @LF & @LF & "Would you like to view the INI file?")
    If $answer = 6 Then 
        Run("notepad.exe .\PixelSearch.ini")
        Exit
    Else    
        Exit
    EndIf
EndFunc

Func Stop()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

- run "Pixel Area Find.au3"

- bring up the forum and have my avatar visible

- press ` (tilda key)

The mouse will move to my avatar...

LAr.

Edited by 1905russell

Share this post


Link to post
Share on other sites

If you use big daddy's script for recording

then on the Pixel Area Find.au3

Global $pixel = Int(IniRead(".\PixelSearch.ini","Main","PixelColor","-1"))

should be

Global $pixel = Int(IniRead(".\PixelSearch.ini","Main","PixelColorDec","-1"))

there are three other changes to make this work

So using big daddy's script to record - this will work.

Global Const $SM_VIRTUALWIDTH = 78
Global Const $SM_VIRTUALHEIGHT = 79

Global $pixel = Int(IniRead(".\PixelSearch.ini","Main","PixelColorDec","-1"))
Global $chksum = IniRead(".\PixelSearch.ini","Main","PixelCheckSum","-1")
If $pixel = -1 Or $chksum = -1 Then
    MsgBox(4096,"Error","Could not read INI")
    Exit
EndIf

$VIRTUALDESKTOPWIDTH = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALWIDTH)
$VIRTUALDESKTOPWIDTH = $VIRTUALDESKTOPWIDTH[0]
$VIRTUALDESKTOPHEIGHT = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALHEIGHT)
$VIRTUALDESKTOPHEIGHT = $VIRTUALDESKTOPHEIGHT[0]

HotKeySet("`","find")

While 1
    ToolTip("Press ` (Tilda key) to" & @LF & "find the area in PixelSearch.ini.")
    Sleep(100)
WEnd

Func find()
    $x = 0
    $y = 0
    $ypixel = $VIRTUALDESKTOPHEIGHT - 1
    While 1
        $xy = PixelSearch($x,$y,$VIRTUALDESKTOPWIDTH - 1,$ypixel,$pixel)
        If @error And $ypixel = ($VIRTUALDESKTOPHEIGHT - 1)Then
            MsgBox(4096,"Error","Could not find area.")
            Exit
        ElseIf @error Then
            $y = $ypixel + 1
            $ypixel = ($VIRTUALDESKTOPHEIGHT - 1)
            $x = 0
        ElseIf String($chksum) = String(PixelCheckSum($xy[0]-5,$xy[1]-5,$xy[0]+5,$xy[1]+5)) Then
            MouseMove($xy[0],$xy[1])
            ToolTip("There it is.")
            Sleep(3000)
            Exit
        Else
            $y = $xy[1]
            $ypixel = $y
            $x = $xy[0] + 1
        EndIf
    WEnd
EndFunc

Thanks for the lesson Larry

Why did I have to convert both $chksum and PixelSearch to strings for this to work? Both these rounded intergers never equaled zero when deducted. Difference in 1000s? Match 3.x - 3.x= +2000. Both len 12? Why - Thanks?

Share this post


Link to post
Share on other sites

I could have sworn I read this post a while ago... and now it's at the top?


[center]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.[/center]

Share this post


Link to post
Share on other sites

I could have sworn I read this post a while ago... and now it's at the top?

I edited a sep 2nd posting today and it got lost back there. So I redid it as a today posting. How did you see it before I only figured it out today?

Share this post


Link to post
Share on other sites

I edited a sep 2nd posting today and it got lost back there. So I redid it as a today posting. How did you see it before I only figured it out today?

I read it when you first posted it.

[center]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.[/center]

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