Sign in to follow this  
Followers 0
Malkey

Tooltip - Displays Pixel color & X, Y position.

3 posts in this topic

#1 ·  Posted (edited)

I hope you find this interesting and useful.

Local $aPos, $sColor, $iPosX, $iPosY

; Click right mouse button, or, press Escape key, or, press Spacebar to exit.
While IsPressed(2) + IsPressed('1B') + IsPressed(20) = 0
    $aPos = MouseGetPos()
    $sColor = GetPixel(0, $aPos[0], $aPos[1])   
    $iPosX = ($aPos[0] - 100) * ($aPos[0] > @DesktopWidth * 0.90) + ($aPos[0] <= @DesktopWidth * 0.90) * ($aPos[0] + 3)
    $iPosY = ($aPos[1] - 30) * ($aPos[1] > @DesktopHeight * 0.96) + ($aPos[1] <= @DesktopHeight * 0.96) * ($aPos[1] + 3)
    ToolTip("Color is: " & $sColor & @CRLF & "  X: " & $aPos[0] & "   Y: " & $aPos[1], $iPosX, $iPosY)
    Sleep(10)
WEnd

Func GetPixel($handle, $x, $y) ; Returns color (0xRRGGBB) as a string
    Local $dc, $icolor, $iRet
    $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle)
    $icolor = DllCall("gdi32.dll", "int", "GetPixel", "hwnd", $dc[0], "int", $x, "int", $y)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $handle, "int", $dc[0])
    ; Converts RGB to BGR colour and visa-versa
    $iRet = BitAND(BitShift(String(Binary($icolor[0])), 8), 0xFFFFFF) 
    Return "0x" & Hex($iRet, 6)
EndFunc   ;==>GetPixel

; Copied from ...\Include\Misc.au3  File
Func IsPressed($sHexKey)
    Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc   ;==>IsPressed

Edit: Replaced DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0])

with DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $handle, "int", $dc[0])

Edited by Malkey

Share this post


Link to post
Share on other sites



You don't need the GetPixel :)

Just use

$sColor = "0x" & Hex(PixelGetColor($aPos[0],$aPos[1]),6)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

You don't need the GetPixel :)

Just use

$sColor = "0x" & Hex(PixelGetColor($aPos[0],$aPos[1]),6)
Thanks for the heads up.

I admire your work.

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