Jump to content

Color grab


Hest
 Share

Recommended Posts

Inspired by this: http://www.autoitscript.com/forum/index.php?showtopic=93250 (Pixel Grab) I made an extended version.

Might be usefull to someone.

post-33176-1241512453_thumb.jpg

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
Global $pixel_last
Global $color_label[8]
Global $label_color[8] = [1, 2, 3, 4, 5, 6, 7]
Global $last_label = 1

HotKeySet("{F11}","clip")
HotKeySet("{ESC}","endme")

#Region ### START Koda GUI section ### Form=
$Pixelgrab_form = GUICreate("Color Grab", 177, 85, 797, 354)
GUISetBkColor(0xFFFFFF)
$font_group     = GUICtrlCreateGroup("Color", 12, 8, 148, 65)
$font_label     = GUICtrlCreateLabel("", 46, 32, 90, 21)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
;GUICtrlCreateGroup("", -99, -99, 1, 1)
For $i = 1 To 7
    Local $step = 20
    $color_label[$i] = GUICtrlCreateLabel("", $step * $i, 56, 12, 12, $SS_SUNKEN)
Next
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    sleep(100)
    Call("grab")
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func grab()
    $pos = MouseGetPos()
    $pixel_hex = Hex(PixelGetColor($pos[0],$pos[1]), 6)
    
        If $pixel_last <> $pixel_hex Then
        GUICtrlSetData($font_label, "#" & $pixel_hex)
    EndIf
    $pixel_last = $pixel_hex
EndFunc

Func clip()
    ClipPut ("#" & $pixel_last)
    Local $color = "0x" & $pixel_last
    If $last_label > 7 Then 
        $last_label = 7
        For $i = 2 To 7
            GUICtrlSetBkColor($color_label[$i - 1], $label_color[$i])
            $label_color[$i - 1] = $label_color[$i]
        Next
    EndIf
    GUICtrlSetBkColor($color_label[$last_label], $color)

    $label_color[$last_label] = $color
    $last_label = $last_label + 1
EndFunc

Func endme()
    Exit
EndFunc
Edited by Hest
Software:Model Train Calculator (Screen)Autoit3 beginner!
Link to comment
Share on other sites

Glad you like it. Not sure if I have done it the best way though ^_^ still learning.

Quick Tips:

When posting soure code use [-autoit] [-/autoit] ( without - ) tags.

And tidy it up a lil ;)

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
Global $pixel_last
Global $color_label[8]
Global $label_color[8] = [1, 2, 3, 4, 5, 6, 7]
Global $last_label = 1

HotKeySet("{F11}","clip")
HotKeySet("{ESC}","endme")

$Pixelgrab_form    = GUICreate("Color Grab", 177, 85, 797, 354)
GUISetBkColor(0xFFFFFF)
$font_group     = GUICtrlCreateGroup("Color", 12, 8, 148, 65)
$font_label     = GUICtrlCreateLabel("", 46, 32, 90, 21)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
;GUICtrlCreateGroup("", -99, -99, 1, 1)
For $i = 1 To 7
    Local $step = 20
    $color_label[$i] = GUICtrlCreateLabel("", $step * $i, 56, 12, 12, $SS_SUNKEN)
Next
GUISetState(@SW_SHOW)

While 1
    sleep(100)
    Call("grab")
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func grab()
    $pos = MouseGetPos()
    $pixel_hex = Hex(PixelGetColor($pos[0],$pos[1]), 6)
    
    If $pixel_last <> $pixel_hex Then
        GUICtrlSetData($font_label, "#" & $pixel_hex)
    EndIf
    $pixel_last = $pixel_hex
EndFunc ;==>Grab

Func clip()
    ClipPut ("#" & $pixel_last)
    Local $color = "0x" & $pixel_last
    If $last_label > 7 Then
        $last_label = 7
            For $i = 2 To 7
                GUICtrlSetBkColor($color_label[$i - 1], $label_color[$i])
                $label_color[$i - 1] = $label_color[$i]
            Next
    EndIf
    GUICtrlSetBkColor($color_label[$last_label], $color)

    $label_color[$last_label] = $color
    $last_label = $last_label + 1
EndFunc ;==>Clip

Func endme()
    Exit
EndFunc ;==>EndMe
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...