Sign in to follow this  
Followers 0
aommaster

Find Next Pixel

2 posts in this topic

Hi guys!

I'm trying to write a program that searches for a pixel which has a hex value exactly equal to what a user types into a gui.

So far, what I have been able to do is to have the gui minimise itself, find the pixel, move the mouse to that posisiton, and store that position into an array.

Now, it also enables a "Find Next" button. I want the next loop to work so that it will start searching the screen again, from top to bottom on the following conditions:

1.Pixels found before are ignored

2.Pixels within 5 pixels up, down, left, and right are also ignored.

What this in effect does is that it keeps searching the screen for the pixels from top to bottom, left to right, searching those pixels until it reaches the very end of the screen.

Any ideas on how to do that?

Thanks guys!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I whipped this up...

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

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

$color = InputBox("Color","Color to find: e.g. FF00FF")
$color = Dec($color)

HotKeySet("{TAB}","cont")
HotKeySet("{ESC}","quit")

find($color)

MsgBox(4096,"Color","Done finding colors.")

Func find($pixel)
    $x = 0
    $y = 0
    $ypixel = $VIRTUALDESKTOPHEIGHT - 1
    While 1
        $xy = PixelSearch($x,$y,$VIRTUALDESKTOPWIDTH - 1,$ypixel,$pixel)
        If @error And $ypixel = ($VIRTUALDESKTOPHEIGHT - 1)Then
            Return
        ElseIf @error Then
            $y = $ypixel + 1
            $ypixel = ($VIRTUALDESKTOPHEIGHT - 1)
            $x = 0
        Else
            MouseMove($xy[0],$xy[1])
            ToolTip("PRESS [TAB] to continue, [ESC] to quit.")
            While Not $bCont
                Sleep(20)
            WEnd
            $bCont = False
            $y = $xy[1]
            $ypixel = $y
            $x = $xy[0] + 1
        EndIf
    WEnd
EndFunc

Func cont()
    $bCont = True
EndFunc

Func quit()
    Exit
EndFunc
Thanks! Edited by Larry

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