|
| 1 | +#NoEnv |
| 2 | +SendMode Input |
| 3 | +SetWorkingDir %A_ScriptDir% |
| 4 | +#SingleInstance, Force |
| 5 | + |
| 6 | +; Setup |
| 7 | +OnExit, Exit |
| 8 | +xcolorIcon := A_ScriptFullPath |
| 9 | + |
| 10 | +; Hotkeys |
| 11 | +Hotkey, RButton, CatchColor ; HEX (Default) |
| 12 | +Hotkey, ^RButton, CatchColor ; RGB |
| 13 | +Hotkey, Esc, Exit ; Assigning Esc key to Exit subroutine |
| 14 | + |
| 15 | +; Initiation |
| 16 | +Traytip, xcolor:, RIGHTCLICK to copy HEX value`nAdd CTRL for RGB value, 5 |
| 17 | +SetSystemCursor("IDC_CROSS") ; Set the cursor to IDC_CROSS |
| 18 | +RestoreCursorsOnExit := true ; Flag to restore cursors on exit |
| 19 | + |
| 20 | +; MAIN LOOP: Pick Color |
| 21 | +Loop |
| 22 | +{ |
| 23 | + CoordMode, Mouse, Screen |
| 24 | + MouseGetPos, X, Y |
| 25 | + PixelGetColor, Color, X, Y, RGB |
| 26 | + Color := "0x" . SubStr(Color, 3) ; Ensure color is in correct format |
| 27 | + |
| 28 | + ; Show color in GUI |
| 29 | + if GetKeyState("LControl") |
| 30 | + ColorMessage := HexToRGB(Color, "Message") |
| 31 | + else |
| 32 | + ColorMessage := "#" . SubStr(Color, 3) ; Prepend # to HEX color |
| 33 | + |
| 34 | + Gui, xcolor:Color, % Color |
| 35 | + Tooltip, % ColorMessage |
| 36 | + CoordMode, Pixel |
| 37 | + mX := X - 30 ; Offset Tooltip from Mouse |
| 38 | + mY := Y - 80 |
| 39 | + Gui, xcolor:-Caption +ToolWindow +LastFound +AlwaysOnTop +Border |
| 40 | + Gui, xcolor:Show, NoActivate x%mX% y%mY% w60 h60 |
| 41 | +} |
| 42 | + |
| 43 | +return |
| 44 | + |
| 45 | +CatchColor: ; Catch Hover'd color |
| 46 | +if (A_ThisHotkey = "^RButton") |
| 47 | + Out := "RGB" |
| 48 | + |
| 49 | +; Continue processing color |
| 50 | +GoSub, ColorPicked |
| 51 | +return |
| 52 | + |
| 53 | +ColorPicked: |
| 54 | +Color := "0x" . SubStr(Color, 3) ; Ensure color is in correct format |
| 55 | + |
| 56 | +If (Out = "RGB") |
| 57 | +{ |
| 58 | + OutColor := HexToRGB(Color, "RGB") |
| 59 | + OutMsg := HexToRGB(Color, "Message") |
| 60 | + Clipboard := OutMsg |
| 61 | +} |
| 62 | +else |
| 63 | +{ |
| 64 | + OutColor := HexToRGB(Color) |
| 65 | + OutMsg := OutColor |
| 66 | + Clipboard := OutColor |
| 67 | +} |
| 68 | + |
| 69 | +Traytip, xcolor:, % OutMsg " picked" |
| 70 | +RestoreCursors() |
| 71 | +Gui, xcolor:Destroy |
| 72 | +Sleep, 500 |
| 73 | +Hotkey, ^RButton, Off |
| 74 | +Hotkey, RButton, Off |
| 75 | +Sleep, 1500 |
| 76 | +GoSub, Exit |
| 77 | +return |
| 78 | + |
| 79 | +Exit: ; Exit subroutine |
| 80 | +if (RestoreCursorsOnExit) |
| 81 | + RestoreCursors() |
| 82 | +ExitApp |
| 83 | +return |
| 84 | + |
| 85 | +; FUNCTIONS |
| 86 | +HexToRGB(Color, Mode="") |
| 87 | +{ |
| 88 | + R := SubStr(Color, 3, 2) |
| 89 | + G := SubStr(Color, 5, 2) |
| 90 | + B := SubStr(Color, 7, 2) |
| 91 | + |
| 92 | + if (Mode = "Message") |
| 93 | + return "R: " . R . ", G: " . G . ", B: " . B |
| 94 | + else if (Mode = "RGB") |
| 95 | + return R . "," . G . "," . B |
| 96 | + else |
| 97 | + return "#" . SubStr(Color, 3) ; Keep "#" for HTML color codes |
| 98 | +} |
| 99 | + |
| 100 | +RestoreCursors() |
| 101 | +{ |
| 102 | + SPI_SETCURSORS := 0x57 |
| 103 | + DllCall("SystemParametersInfo", UInt, SPI_SETCURSORS, UInt, 0, UInt, 0, UInt, 0) |
| 104 | +} |
| 105 | + |
| 106 | +SetSystemCursor( Cursor = "", cx = 0, cy = 0 ) |
| 107 | +{ |
| 108 | + BlankCursor := 0, SystemCursor := 0, FileCursor := 0 ; init |
| 109 | + |
| 110 | + SystemCursors = 32512IDC_ARROW,32513IDC_IBEAM,32514IDC_WAIT,32515IDC_CROSS |
| 111 | + ,32516IDC_UPARROW,32640IDC_SIZE,32641IDC_ICON,32642IDC_SIZENWSE |
| 112 | + ,32643IDC_SIZENESW,32644IDC_SIZEWE,32645IDC_SIZENS,32646IDC_SIZEALL |
| 113 | + ,32648IDC_NO,32649IDC_HAND,32650IDC_APPSTARTING,32651IDC_HELP |
| 114 | + |
| 115 | + If Cursor = ; empty, so create blank cursor |
| 116 | + { |
| 117 | + VarSetCapacity( AndMask, 32*4, 0xFF ), VarSetCapacity( XorMask, 32*4, 0 ) |
| 118 | + BlankCursor = 1 ; flag for later |
| 119 | + } |
| 120 | + Else If SubStr( Cursor,1,4 ) = "IDC_" ; load system cursor |
| 121 | + { |
| 122 | + Loop, Parse, SystemCursors, `, |
| 123 | + { |
| 124 | + CursorName := SubStr( A_Loopfield, 6, 15 ) ; get the cursor name, no trailing space with substr |
| 125 | + CursorID := SubStr( A_Loopfield, 1, 5 ) ; get the cursor id |
| 126 | + SystemCursor = 1 |
| 127 | + If ( CursorName = Cursor ) |
| 128 | + { |
| 129 | + CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID ) |
| 130 | + Break |
| 131 | + } |
| 132 | + } |
| 133 | + If CursorHandle = ; invalid cursor name given |
| 134 | + { |
| 135 | + Msgbox,, SetCursor, Error: Invalid cursor name |
| 136 | + CursorHandle = Error |
| 137 | + } |
| 138 | + } |
| 139 | + Else If FileExist( Cursor ) |
| 140 | + { |
| 141 | + SplitPath, Cursor,,, Ext ; auto-detect type |
| 142 | + If Ext = ico |
| 143 | + uType := 0x1 |
| 144 | + Else If Ext in cur,ani |
| 145 | + uType := 0x2 |
| 146 | + Else ; invalid file ext |
| 147 | + { |
| 148 | + Msgbox,, SetCursor, Error: Invalid file type |
| 149 | + CursorHandle = Error |
| 150 | + } |
| 151 | + FileCursor = 1 |
| 152 | + } |
| 153 | + Else |
| 154 | + { |
| 155 | + Msgbox,, SetCursor, Error: Invalid file path or cursor name |
| 156 | + CursorHandle = Error ; raise for later |
| 157 | + } |
| 158 | + If CursorHandle != Error |
| 159 | + { |
| 160 | + Loop, Parse, SystemCursors, `, |
| 161 | + { |
| 162 | + If BlankCursor = 1 |
| 163 | + { |
| 164 | + Type = BlankCursor |
| 165 | + %Type%%A_Index% := DllCall( "CreateCursor" |
| 166 | + , Uint,0, Int,0, Int,0, Int,32, Int,32, Uint,&AndMask, Uint,&XorMask ) |
| 167 | + CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 ) |
| 168 | + DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) ) |
| 169 | + } |
| 170 | + Else If SystemCursor = 1 |
| 171 | + { |
| 172 | + Type = SystemCursor |
| 173 | + CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID ) |
| 174 | + %Type%%A_Index% := DllCall( "CopyImage" |
| 175 | + , Uint,CursorHandle, Uint,0x2, Int,cx, Int,cy, Uint,0 ) |
| 176 | + CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 ) |
| 177 | + DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) ) |
| 178 | + } |
| 179 | + Else If FileCursor = 1 |
| 180 | + { |
| 181 | + Type = FileCursor |
| 182 | + %Type%%A_Index% := DllCall( "LoadImageA" |
| 183 | + , UInt,0, Str,Cursor, UInt,uType, Int,cx, Int,cy, UInt,0x10 ) |
| 184 | + DllCall( "SetSystemCursor", Uint,%Type%%A_Index%, Int,SubStr( A_Loopfield, 1, 5 ) ) |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | +} |
0 commit comments