Sign in to follow this  
Followers 0
Der_Andi

ColorPicker

16 posts in this topic

I searched, but i didn't found what i need. So i wrote it by myself.

A simple color picker. Retrieves the color under your mouse pointer and shows it in AutoIt-friendly hex format.

Press the button, to copy the "0x......"-value into clipboard.

Hit the [Ctrl]-Key on your keyboard once, to lock/unlock the GUI.

That's all. Happy programming. :whistle:

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

GuiCreate("ColorPicker", 170, 80, -1, -1, -1, $ws_ex_topmost + $ws_ex_toolwindow)
GUISetFont(9, 400, 0, "Verdana")
$lbl_color = GuiCtrlCreateLabel("", 10, 10, 60, 60, $ss_center + $ss_centerimage)
GUICtrlSetFont(-1, 9, 600)
$lbl_hex = GuiCtrlCreateLabel("0x", 80, 10, 80, 20, $ss_center + $ss_sunken + $ss_centerimage)
$cmd_copy = GuiCtrlCreateButton("", 80, 40, 80, 30, $bs_icon)
GUICtrlSetImage($cmd_copy, "shell32.dll", 134, 0)
GUICtrlSetTip($cmd_copy, "Copy hex-value into clipboard")

$last = 0
GuiSetState()
While 1
    $msg = GuiGetMsg()
    $col = PixelGetColor(MouseGetPos(0), MouseGetPos(1))
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $col <> $last  And GUICtrlRead($lbl_color) = ""
        GUICtrlSetData($lbl_hex, "0x" & Hex($col, 6))
        GUICtrlSetBkColor($lbl_color, "0x" & Hex($col, 6))
        $last = $col
    Case _IsPressed("11") = 1
        If GUICtrlRead($lbl_color) = "[Lock]" Then
            GUICtrlSetData($lbl_color, "")
        Else
            GUICtrlSetData($lbl_color, "[Lock]")
            If $col < 3000000 Then
                GUICtrlSetColor($lbl_color, 0xFFFFFF)
            Else
                GUICtrlSetColor($lbl_color, 0x000000)
            EndIf
        EndIf
        Sleep(200)
    Case $msg = $cmd_copy
        ClipPut(GUICtrlRead($lbl_hex))
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites



I know, there are 100's of those tools out there. :whistle:

Share this post


Link to post
Share on other sites

well, the one's i tested, didn't exactly fulfill my needs.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

maybe one of you guys could add a 15 by 15 pixels window that would act as a magnifing glass, attached to the mouse cursor...

Share this post


Link to post
Share on other sites

maybe one of you guys could add a 15 by 15 pixels window that would act as a magnifing glass, attached to the mouse cursor...

Try the search button. It exists.

Share this post


Link to post
Share on other sites

I know, there are 100's of those tools out there. :whistle:

Color Cop ==>95kb

hard to beat at that size and price :)

Share this post


Link to post
Share on other sites

attached to the mouse cursor...

Ah, you prefer a GUI that hunts for your mouse?

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

GuiCreate("ColorPicker", 170, 80, -1, -1, -1, $ws_ex_topmost + $ws_ex_toolwindow)
GUISetFont(9, 400, 0, "Verdana")
$lbl_color = GuiCtrlCreateLabel("", 10, 10, 60, 60, $ss_center + $ss_centerimage)
GUICtrlSetFont(-1, 9, 600)
$lbl_hex = GuiCtrlCreateLabel("0x", 80, 10, 80, 20, $ss_center + $ss_sunken + $ss_centerimage)
$cmd_copy = GuiCtrlCreateButton("", 80, 40, 80, 30, $bs_icon)
GUICtrlSetImage($cmd_copy, "shell32.dll", 134, 0)
GUICtrlSetTip($cmd_copy, "Copy hex-value into clipboard")

$last = 0
GuiSetState()
While 1
    $msg = GuiGetMsg()
    
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    If GUICtrlRead($lbl_color) = "" Then
        Select
            Case $x < @DesktopWidth/2 And $y < @DesktopHeight/2     ;top-left
                $offX = 20
                $offY = 20
            Case $x > @DesktopWidth/2 And $y < @DesktopHeight/2     ;top-right
                $offX = -20 - 176
                $offY = 20
            Case $x < @DesktopWidth/2 And $y > @DesktopHeight/2     ;bottom-left
                $offX = 20
                $offY = -20 - 106
            Case $x > @DesktopWidth/2 And $y > @DesktopHeight/2     ;bottom-right
                $offX = -20 - 176
                $offY = -20 - 106
        EndSelect
        WinMove("ColorPicker", "0x", $x + $offX, $y + $offY)
    EndIf
    
    $col = PixelGetColor($x, $y)
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $col <> $last  And GUICtrlRead($lbl_color) = ""
        GUICtrlSetData($lbl_hex, "0x" & Hex($col, 6))
        GUICtrlSetBkColor($lbl_color, "0x" & Hex($col, 6))
        $last = $col
    Case _IsPressed("11") = 1
        If GUICtrlRead($lbl_color) = "[Lock]" Then
            GUICtrlSetData($lbl_color, "")
        Else
            GUICtrlSetData($lbl_color, "[Lock]")
            If $col < 3000000 Then
                GUICtrlSetColor($lbl_color, 0xFFFFFF)
            Else
                GUICtrlSetColor($lbl_color, 0x000000)
            EndIf
        EndIf
        Sleep(200)
    Case $msg = $cmd_copy
        ClipPut(GUICtrlRead($lbl_hex))
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites

Color Cop ==>95kb

hard to beat at that size and price :whistle:

Or my personal favorite

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Why would you make another?

To me it always seemed like one of those scripts that everyone has to make their own version of at one time or another. Almost like a rite of passage. :whistle:

...I made one too (actually I made two, but the first one was kinda crappy)...

Source is included in the .zip.

The main things I added in mine were a few options I never saw in others. You can fade from one colour to another (gradient), invert the colours, save swatches (which are really just ini files). I wrote a rather long readme one night while I was at work.

Edited by Saunders

Share this post


Link to post
Share on other sites

Not quite sure who you're talking to HardHackz, but I would guess the answer to your question is that someone is using the IsPressed UDF to check to see if the Ctrl key is pressed. Check the manual for IsPressed.

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