Jump to content

ShareX.exe -ColorPicker


ioa747
 Share

Recommended Posts

ShareX.exe -ColorPicker  

for those who don't know !
ShareX is a free and open source program -  Screen capture, file sharing and productivity tool
ColorPicker   It is a separate tool of his where you can call it with ShareX.exe -ColorPicker

I use it Regularly, so I said to order in AutoIt services  :)

if you choose a color by double-clicking in scite on the hex color , you can then use get Get to get it, to see the color, or use Set to set it, change it
with  <-- button insert color name as comment, at the cursor position

 

; https://www.autoitscript.com/forum/topic/209749-sharexexe-colorpicker/
;------------------------------------------------------------------------------
; Title...........: CollorSX.au3
; Description.....: ShareX.exe -ColorPicker
;------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StringConstants.au3>

Global $ClipBack, $ClipData, $hSciTE, $hCtrlHnd, $hShareX, $ShareX_Pos, $iState, $ColorName
Global $hGhostGUI, $idButtonGet, $idButtonSet, $idColorName, $idButtonCopyTxt, $ActStatus, $TmpStatus, $HexColor

If Not WinExists("[CLASS:SciTEWindow]") Then
    Exit
EndIf

; copy selected text from SciTE
$ClipBack = ClipGet() ; backup clip data
$hSciTE = WinActivate("[CLASS:SciTEWindow]")
$hCtrlHnd = ControlGetFocus($hSciTE)
$hCtrlHnd = ControlGetHandle($hSciTE, '', $hCtrlHnd)
_SendMessage($hCtrlHnd, $WM_COPY)
$ClipData = ClipGet()


LoadShareX("C:\Program Files\ShareX\ShareX.exe")


$hShareX = WinWait("ShareX - Color picker")
WinActivate($hShareX)
ControlClick($hShareX, "", "[NAME:btnClipboardColorPicker]")
$ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]")

$ShareX_Pos = WinGetPos($hShareX)

; get the ShareX win color
$HexColor = PixelGetColor($ShareX_Pos[0] + 550, $ShareX_Pos[1] + 50)
$HexColor = "0x" & Hex($HexColor, 6)

ClipPut($ClipBack) ; Restore backup clip data
; Set the ShareX window as being ontop
ConsoleWrite("$WinOnTop=" & WinSetOnTop($hShareX, "", $WINDOWS_ONTOP) & @CRLF)

$hGhostGUI = GUICreate('GhostGUI', 210, 43, $ShareX_Pos[0] + 475, $ShareX_Pos[1] + 320, $WS_POPUP, $WS_EX_TOOLWINDOW, $hShareX)
GUISetBkColor($HexColor)

$idColorName = GUICtrlCreateEdit($ColorName, 3, 1, 180, 19, $ES_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x272727)

$idButtonCopyTxt = GUICtrlCreateButton("<--", 183, 0, 24, 21)

$idButtonGet = GUICtrlCreateButton("Get", 3, 23, 100, 20)
$idButtonSet = GUICtrlCreateButton("Set", 107, 23, 100, 20)

; Display the GUI.
GUISetState(@SW_SHOW, $hGhostGUI)
WinActivate($hShareX)

;Yellow 0xFFFF00 ;Gray 0x7E7E7E ;Goldenrod 0xE39024 ;Lawn green  0x75DC19  ;Dark slate gray 0x063549

;*********************************************************************
While WinExists($hShareX)

    If Not WinExists($hSciTE) Then
        Exit
    EndIf

    ; Retrieve the state of the ShareX window
    $iState = WinGetState($hShareX)

    Switch $iState
        Case 7, 15
            $ActStatus = @SW_SHOW
        Case 5, 23
            $ActStatus = @SW_HIDE
    EndSwitch

    If $ActStatus <> $TmpStatus Then
        ;ConsoleWrite("$iState=" & $iState & @CRLF)
        GUISetState($ActStatus, $hGhostGUI)
        $TmpStatus = $ActStatus
        If $ActStatus = @SW_SHOW Then
            WinActivate($hShareX)
            $HexColor = "0x" & ControlGetText($hShareX, "", "[NAME:txtHex]")
            $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]")
            ConsoleWrite("# " & $HexColor & " ; " & $ColorName & @CRLF)
            GUICtrlSetData($idColorName, $ColorName)
        EndIf
    EndIf

    If WinActive($hShareX) Then
        $ShareX_Pos = WinGetPos($hShareX)
        WinMove($hGhostGUI, "", $ShareX_Pos[0] + 475, $ShareX_Pos[1] + 320)
        $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]")
        If $ColorName <> GUICtrlRead($idColorName) Then
            GUICtrlSetData($idColorName, $ColorName)
        EndIf
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $idButtonCopyTxt
            $ClipBack = ClipGet()     ; backup clip data
            ClipPut(";" & GUICtrlRead($idColorName))
            WinActivate($hSciTE)
            _SendMessage($hCtrlHnd, $WM_PASTE)
            Global $SpaceCnt = 2
            StringReplace(ClipGet(), " ", " ", 0, $STR_CASESENSE)
            If @extended >= 1 Then
                $SpaceCnt += @extended
            EndIf

            Send("+^{LEFT " & $SpaceCnt & "}")
            ClipPut($ClipBack)        ; Restore backup clip data

        Case $idButtonGet
            $ClipBack = ClipGet()    ; backup clip data
            _SendMessage($hCtrlHnd, $WM_COPY)
            ControlClick($hShareX, "", "[NAME:btnClipboardColorPicker]")
            $HexColor = "0x" & ControlGetText($hShareX, "", "[NAME:txtHex]")
            $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]")
            ConsoleWrite("- Get " & $HexColor & " ; " & $ColorName & @CRLF)
            GUICtrlSetData($idColorName, $ColorName)
            ClipPut($ClipBack)        ; Restore backup clip data

        Case $idButtonSet
            $ClipBack = ClipGet()     ; backup clip data
            $HexColor = "0x" & ControlGetText($hShareX, "", "[NAME:txtHex]")
            $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]")
            ClipPut($HexColor)
            WinActivate($hSciTE)
            _SendMessage($hCtrlHnd, $WM_PASTE)
            Send("+^{LEFT}")
            ConsoleWrite("+ Set " & $HexColor & " ; " & $ColorName & @CRLF)
            GUICtrlSetData($idColorName, $ColorName)
            ClipPut($ClipBack)        ; Restore backup clip data

    EndSwitch

    Sleep(10)
WEnd
;*********************************************************************

Exit

;----------------------------------------------------------------------------------------
Func LoadShareX($sFullPath)
    If Not WinExists("ShareX - Color picker") Then
        If Not FileExists($sFullPath) Then $sFullPath = @ScriptDir & "\ShareX.exe"
        If Not FileExists($sFullPath) Then $sFullPath = @ScriptDir & "\ShareX\ShareX.exe"
        If Not FileExists($sFullPath) Then Exit MsgBox(262144, StringTrimRight(@ScriptName, 4), "Kindly tell the script where to find ShareX.exe, bye now.", 10)
        Run('"' & $sFullPath & '" -ColorPicker')
    EndIf
EndFunc   ;==>LoadShareX

don't forget it's still under development !

230306-104740-549_SciTE_jtDBd.thumb.png.

 

:) Please, leave your comments and experiences here.

thank you very much !

 

PS

for those who have a portable version of ShareX , don't forget to properly update line 30

LoadShareX("C:\Program Files\ShareX\ShareX.exe")

 

Edited by ioa747
UpDate

I know that I know nothing

Link to comment
Share on other sites

nice :)

LoadIfNeeded()
Func LoadIfNeeded()
    Local $sFullPath = "C:\Program Files\ShareX\ShareX.exe"
    If Not WinExists("ShareX - Color picker") Then
        If Not FileExists($sFullPath) Then $sFullPath = @ScriptDir & "\ShareX.exe"
        If Not FileExists($sFullPath) Then $sFullPath = @ScriptDir & "\ShareX\ShareX.exe"
        If Not FileExists($sFullPath) Then Exit MsgBox(262144, StringTrimLeft(@ScriptName, 4), "Kindly tell the script where to find ShareX.exe, bye now.", 10)
        Run('"' & $sFullPath &  '" -ColorPicker' )
    EndIf
EndFunc

I didn't get how it worked. I'm using it in portable mode.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

@argumentum  I'm glad you like it, I enjoyed it too

You are right, in the beginning, in the first editions, and I had it portable, but over time it won a place in the installed programs.
nevertheless, your addition is a nice touch, that's why I adopted it, and ReUpDate thanks for that

and since you expressed the, I didn't get how it worked.

ControlClick($hShareX, "", "[NAME:btnClipboardColorPicker]")

the rest is simple give and take with GUI

I think this will solve your questions

PS
in the function you posted, StringTrimLeft :D  garlic - onion

Thanks for everything ! :)

I know that I know nothing

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