Jump to content
Sign in to follow this  
onestcoder

Get Hex Color at Mouse POS

Recommended Posts

onestcoder

Get Color @ Mouse POS

This is a modified version of Colour Under Mouse by James Brooks aka Secure_ICT

Thanks Secure_ICT

#include <GuiConstants.au3>
#include <Color.au3>
#include <Misc.au3>

$DLL = DllOpen("user32.dll")
Global $Paused
Global $Color, $hexcolor
HotKeySet("{PAUSE}", "TogglePause")

$GUI = GuiCreate("GetColor", 210, 69, -1, -1)

$Label_1 = GUICtrlCreateLabel("", 10, 10, 130, 20)
$Label_2 = GuiCtrlCreateLabel("", 10, 30, 130, 20)
$Label_3 = GuiCtrlCreateLabel("Press PAUSE or ESC!", 10, 50, 130, 20)
$a =GuiCtrlCreateGraphic(150, 10, 50, 50)

WinSetOnTop($GUI, "", 1)
GUISetState(@SW_SHOW)

While Not _IsPressed("1B", $DLL)
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf
    Sleep(100)
    $Color = _GetColor()
    GUICtrlSetBkColor($a ,$Color)
    _ColorShow()
    _Mousepos()
WEnd

DllClose($DLL)

WinActivate($GUI)

Func _GetColor()
    $mPos = MouseGetPos()
    Return PixelGetColor($mPos[0], $mPos[1])
EndFunc   ;==>_GetColor

Func _Mousepos()
    $pos = MouseGetPos()
    GUICtrlSetData($Label_2, "POS:  X  " & $pos[0] & "  Y  " & $pos[1])
EndFunc   ;==>_Mousepos

Func _ColorShow()
    $R = Hex(_ColorGetRed($Color), 2)
    $G = Hex(_ColorGetGreen($Color), 2)
    $B = Hex(_ColorGetBlue($Color), 2)
    $hexcolor = "#" & $R & $G & $B
    GUICtrlSetData($Label_1, "Color: " & $hexcolor)
EndFunc   ;==>_ColorShow

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause
Edited by onestcoder

Need a website: http://www.iconixmarketing.com

Share this post


Link to post
Share on other sites
RooperGee

Very nice! Just what I needed, too.


Progress lies not in enhancing what is, but in advancing towards what will be. - Kahlil Gibran

Share this post


Link to post
Share on other sites
Thunder-man

This is great. (I use it for CSS Style)

I have change the Label_1 to Input_1.

So when i klick Pause, I can copy the Hex.

We can also use ClipPut and copy the Hex to the clipboard.

greeting

Thunder-man

Share this post


Link to post
Share on other sites
Manfred

Hello -

a nice tool for programming GUIs. I modified a little more, missing copy-functions.

So I defined hotkeys ctrl-shift-c and ctrl-shift-p and also color-format for putting directly to the clipboard / paste into my programmcode.

Also I remove ESC for closing and instead of polling GUI I prefer GUIOnEventMode.

Gruss

Manfred

; http://www.autoitscript.com/forum/index.php?showtopic=47928
; changed to GuiEvent-Mode - 19.06.2007
; Hotkey ctrl-shift-c copies color to Clipboard - 19.06.2007
; Hotkey ctrl-shift-p copies position to Clipboard - 19.06.2007

#include <D:\COMMON.WIN\autoIT_v3_2\Include\GuiConstants.au3>
#include <D:\COMMON.WIN\autoIT_v3_2\Include\Color.au3>
#include <D:\COMMON.WIN\autoIT_v3_2\Include\Misc.au3>

Opt("GUICloseOnESC", 0)   ;1=ESC  closes, 0=ESC won't close
Opt("GUIOnEventMode", 1)  ;0=disabled, 1=OnEvent mode enabled
Opt("TrayIconHide", 1)    ;0=show, 1=hide tray icon

$DLL = DllOpen("user32.dll")
Global $Paused
Global $Color, $hexcolor
Global $pos

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("^+c", "ColorToClipBoard")
HotKeySet("^+p", "PosToClipBoard")

$GUI = GuiCreate("GetColor", 210, 90, 40, 40)
GuiSetBkColor("0xFFFF9C")

$Label_1 = GUICtrlCreateLabel("", 10, 10, 130, 20)
$Label_2 = GuiCtrlCreateLabel("", 10, 30, 130, 20)
$Label_3 = GuiCtrlCreateLabel("Hotkeys: Pause," &@CRLF &"Ctrl-Shift-C / Ctrl-Shift-P", 10, 50, 130, 30)
  GuiCtrlSetTip($Label_3, "Ctrl-Shift-C = Color to Clipboard" &@CRLF &"Ctrl-Shift-P = Position to Clipboard")
$a =GuiCtrlCreateGraphic(140, 15, 60, 60)

WinSetOnTop($GUI, "", 1)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "ExitEvent")

While 1
    Sleep(100)
    $Color = _GetColor()
    GUICtrlSetBkColor($a ,$Color)
    _ColorShow()
    _Mousepos()
WEnd

; DllClose($DLL)

; WinActivate($GUI)

Func _GetColor()
    $mPos = MouseGetPos()
    Return PixelGetColor($mPos[0], $mPos[1])
EndFunc   ;==>_GetColor

Func _Mousepos()
    $pos = MouseGetPos()
    GUICtrlSetData($Label_2, "POS:  X  " & $pos[0] & "  Y  " & $pos[1])
EndFunc   ;==>_Mousepos

Func _ColorShow()
    $R = Hex(_ColorGetRed($Color), 2)
    $G = Hex(_ColorGetGreen($Color), 2)
    $B = Hex(_ColorGetBlue($Color), 2)
    $hexcolor = "0x" & $R & $G & $B
    GUICtrlSetData($Label_1, "Color : " & $hexcolor)
EndFunc   ;==>_ColorShow

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"')
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func ExitEvent()
    DllClose($DLL)
    Exit
EndFunc

Func ColorToClipBoard()
    ClipPut($hexcolor)
    Beep(700, 99)
    sleep (100)
    Beep(950, 75)
EndFunc

Func PosToClipBoard()
    ClipPut($pos[0] &", " &$pos[1])
    Beep(700, 99)
    sleep (100)
    Beep(950, 75)
EndFunc

Share this post


Link to post
Share on other sites
James

Just to let you know that you dont need to do:

#include <D:\COMMON.WIN\autoIT_v3_2\Include\GuiCons[Ë]LÉÝÂÚ[ÛYH   ÑÌLÐÓÓSSÓÒSÌLØ]]ÒUÝ×ÌÌLÒ[ÛYI3#´6öÆ÷"æS2fwC°¢6æ6ÇVFRfÇC´C¢b3#´4ôÔÔôâåtâb3#¶WFôE÷c5ó"b3#´æ±ÕÀäÈí5¥Í¹ÔÌÐì(oÝ÷ Ù8b³¥ÚºÚ"µÍÚ[ÛYH  ÑÝZPÛÛÝ[Ë]LÉÝÂÚ[ÛYH  ÐÛÛÜ]LÉÝÂÚ[ÛYH Ö62æS2fwC°

Share this post


Link to post
Share on other sites
Manfred

Just to let you know that you dont need to do:

#include <D:\COMMON.WIN\autoIT_v3_2\Include\GuiConstants.au3>
#include <D:\COMMON.WIN\autoIT_v3_2\Include\Color.au3>
#include <D:\COMMON.WIN\autoIT_v3_2\Include\Misc.au3>oÝ÷ Ù8b³¥ÚºÚ"µÍÚ[ÛYH   ÑÝZPÛÛÝ[Ë]LÉÝÂÚ[ÛYH  ÐÛÛÜ]LÉÝÂÚ[ÛYH ÓZØË]LÉÝ

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  

×