Jump to content

ColorPicker


Der_Andi
 Share

Recommended Posts

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
Link to comment
Share on other sites

Link to comment
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
Link to comment
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!"

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 5 weeks later...

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