Jump to content

Some help with pixelsearch, please


Recommended Posts

Hi every1.

I'm obviously here for some help with a part of a script that I just cant seem to get to work no matter what.

What I'm trying to do is:

a) find the size of the user's window,

:) use static coords (depending on window size) to do a pixelsearch. Theoretically, this will check for the pixel colour no matter the user's window size, right???

c) when found do whatever (ie. in this case press enter)

d) if not found, wait until it does appear and then do whatever.

Can some1 please point me in the right direction by looking at my code.....?

func Openingscreencheck()
    AutoItSetOption("MouseCoordMode", 2)
    $size = WinGetClientSize("")
    $sizex = 0.56 * $size[0]
    $sizex2 = 0.61 * $size[0]  ; how small can this search area be for pixelsearch to work??
    $sizey = 0.91 * $size[1]
    $sizey2 = 0.92 * $size[1]
    while 1
            $colourcheck = PixelSearch($sizex, $sizex2, $sizey, $sizey2, 0x989899, 2) 
        If not @error Then
            send("{ENTER}")
          Else
            Sleep(100);this part just sits and waits but how do I make it wait until the colour appears?
        EndIf
    WEnd
EndFunc

Thanks for any help

Link to comment
Share on other sites

Remove the multiplication you are doing. You should give the pixelcoordinates in long/integer values

Search the forum for pixelsearch there are plenty of samples

; Find a pure red pixel in the range 0,0-20,300

$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )

If Not @error Then

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])

EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red

$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )

If Not @error Then

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])

EndIf

Link to comment
Share on other sites

Something like this?

Dim $WindowTitle = "Your window title here"
Dim $PixelColor = 123

While 1
    If WinExists($WindowTitle) Then
        $PixelPosition = _PixelSearchWindow($WindowTitle, "", $PixelColor, 0, 1, 1)
        If Not @error Then MouseClick("left", $PixelPosition[0], $PixelPosition[1], 1, 0)
    EndIf
    Sleep(250)
WEnd


Func _PixelSearchWindow($s_wTitle, $s_wText, $i_pColor, $i_pVariation = 0, $i_pStep = 1, $i_ActivateWindow = False)
    
    If Not WinExists($s_wTitle, $s_wText) Then
        SetError(1)
        Return 0
    EndIf
    
    If $i_ActivateWindow Then
        WinActivate($s_wTitle, $s_wText)
        WinWaitActive($s_wTitle, $s_wText)
    EndIf
    
    Local $a_wPos = WinGetPos($s_wText, $s_wText), $a_Ret
    
    $a_Ret = PixelSearch($a_wPos[0], $a_wPos[1], $a_wPos[0]+$a_wPos[2], $a_wPos[1]+$a_wPos[3], $i_pColor, $i_pVariation, $i_pStep)
    If @error Then
        SetError(@error)
        Return 0
    Else
        SetError(0)
        Return $a_Ret
    EndIf   

EndFunc

Edit:

Added some error checks, and added an option for activating the window first. :)

Edited by FreeFry
Link to comment
Share on other sites

Thanks Freefry, will test it soon.

Why wont my code work? My main aim is to use a certain percentage of the window for the pixelsearch.

I'd like to keep the code in my format (simple, coz I'm simple :) ), solely as a Function (to lessen any changing of my main script I may have to do). I wont really need the error checks and window activating, so which lines can I delete/ rewrite?

Link to comment
Share on other sites

Either use Int(float) / or Round(float)

Round is the best bet, since Int removes everything behind . Example $var = Int(1.999) var is now = 1

You can use it inn this manner:

$sizex = Round(0.56 * $size[0])
    $sizex2 = Round(0.61 * $size[0])
    $sizey = Round(0.91 * $size[1])
    $sizey2 = Round(0.92 * $size[1])
Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Probably why your script doesn't work is because you do not set PixelCoordMode to 2.

func Openingscreencheck()
    AutoItSetOption("MouseCoordMode", 2)
    AutoItSetOption("PixelCoordMode", 2) ; you need to set PixelCoordMode too.
    $size = WinGetClientSize("")
    $sizex = 0.56 * $size[0]
    $sizex2 = 0.61 * $size[0]  ; how small can this search area be for pixelsearch to work??
    $sizey = 0.91 * $size[1]
    $sizey2 = 0.92 * $size[1]
    while 1
            $colourcheck = PixelSearch($sizex, $sizex2, $sizey, $sizey2, 0x989899, 2)
        If not @error Then
            send("{ENTER}")
          Else
            Sleep(100);this part just sits and waits but how do I make it wait until the colour appears?
        EndIf
    WEnd
EndFunc
Link to comment
Share on other sites

Either use Int(float) / or Round(float)

Round is the best bet, since Int removes everything behind . Example $var = Int(1.999) var is now = 1

You can use it inn this manner:

$sizex = Round(0.56 * $size[0])
    $sizex2 = Round(0.61 * $size[0])
    $sizey = Round(0.91 * $size[1])
    $sizey2 = Round(0.92 * $size[1])
I don't belive that's the problem, as I belive PixelSearch rounds the parameters down to an integer automatically...
Link to comment
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
 Share

  • Recently Browsing   0 members

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