Jump to content

PixelSearch can't find my target


Recommended Posts

So, I'm trying to find black pixels in a rectangle. I think my code is quite easy to understand, so I think you will easily see what am I doing. All the coordinates are included:

HotKeySet("{ESC}", "Quit")

Sleep(2000)

While 1
    ; Top left:     (460,  75)
    ; Botton right: (900, 350)

    $Left = 460
    $Top = 75
    $Right = @DesktopWidth - 900
    $Bottom = @DesktopHeight - 350

    $coord = PixelSearch($Left, $Top, $Right, $Bottom, 0x000000, 5, 2)

    If Not @error Then
        MouseClick("left", $coord[0], $coord[1], 1, 0)
        PrintPixel("Pixel at: (" & $coord[0] & ", " & $coord[1] & ")")
    Else
        PrintPixel("Pixel not found!")
    EndIf

    Sleep(10)
WEnd

Func PrintPixel($custom)
    $pos = MouseGetPos()
    ToolTip("X: " & $pos[0] & " Y: " & $pos[1] & " HEX: " & Hex(PixelGetColor($pos[0], $pos[1])) & @CRLF & $custom, $pos[0] + 10, $pos[1] + 5)
EndFunc

Func Quit()
    Exit 0
EndFunc

I uploaded an image which clearly says that there's a 0000000 HEX in that area, but my code just can't find it. Could anyone spot the problem why my script can't find that black point? (by the way, my resolution is 1360*768)

 

Thanks for your help guys :)

Untitled.png

Edited by Unc3nZureD
Link to comment
Share on other sites

It might be that you're skipping the black pixel because you're using a step value of 2, it could be just jumping over it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I dont quite understand the goal, but here is one fixed so that when you mouse over a black pixel the tooltip reflects as such.

 

HotKeySet("{ESC}", "Quit")

While 1

$coord = MouseGetPos()
PixelSearch($coord[0] , $coord[1] , $coord[0] , $coord[1] , 0 , 5 , 1)
    If @Error = 0 Then
        PrintPixel("Pixel at: (" & $coord[0] & ", " & $coord[1] & ")")
    Else
        PrintPixel("Pixel not found!")
    EndIf

    Sleep(10)
WEnd

Func PrintPixel($custom)
    $pos = MouseGetPos()
    ToolTip("X: " & $pos[0] & " Y: " & $pos[1] & " HEX: " & Hex(PixelGetColor($pos[0], $pos[1])) & @CRLF & $custom, $pos[0] + 10, $pos[1] + 5)
EndFunc

Func Quit()
    Exit 0
EndFunc

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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...