Author Topic: RGBhelper script  (Read 12988 times)

lnminente

  • Sr. Member
  • ****
  • Posts: 1049
I have written a small script for helping with the skinning work. Many color pickers stores the color in hexadecimal, but not with the format 123,124,125 to do a fast search or paste it directly between "" in a musicbee skin file.

Pressing Ctrl+Alt+Z it picks and copies the colour under cursor.
When needing more precision run your favourite color picker configuring it autocopying to clipboard with the usual html hex code format. This script watches the clipboard and when finds a string of 7 chars starting with #, converts it to rgb and stores it in the clipboard again with the 123,124,125 format.

Included sources and executable file. I'm not responsible for any damage, try it at your own risk.

RGBhelper

Color picker recommended YS Instant Color Picker: http://youngsmarts.com/index.htm


Autohotkey script:
Code
#SingleInstance, Force
#Persistent
;Some code copied from the help and some from
;http://www.autohotkey.com/community/viewtopic.php?t=45955
Menu, Tray, Icon, RGBhelper.ico

^!z::  ; Control+Alt+Z hotkey.
MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%,RGB
clipboard = % hexToRgb(color)
splashTextOn, , ,  % "Colorpicked: " hexToRgb(color) " copied."
Sleep 1500
splashTextOff
return

OnClipboardChange:
StringLen, check, clipboard

If check = 7
{
StringLeft, check, clipboard, 1

If check = #
{
StringRight, check, clipboard, 6
clipboard = % hexToRgb(clipboard)
ToolTip % "Hex code converted:" clipboard
Sleep 1000
ToolTip  ; Turn off the tip.
}

}
return


rgbToHex(s, d = "") {
   StringSplit, s, s, % d = "" ? "," : d
   SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f
   h := s1 + 0 . s2 + 0 . s3 + 0
   SetFormat, Integer, %f%
   Return, "#" . RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")
}

hexToRgb(s, d = "") {
   SetFormat, Integer, % (f := A_FormatInteger) = "H" ? "D" : f
   Loop, % StrLen(s := RegExReplace(s, "^(?:0x|#)")) // 2
      c%A_Index% := 0 + (h := "0x" . SubStr(s, A_Index * 2 - 1, 2))
   SetFormat, Integer, %f%
   Return, c1 . (d := d = "" ? "," : d) . c2 . d . c3
}

CheckHexC(s, d = "") {
   If InStr(s, (d := d = "" ? "," : d))
      e := hexToRgb(rgbToHex(s, d), d) = s
   Else e := rgbToHex(hexToRgb(s)) = (InStr(s, "#") ? "" : "#"
      . RegExReplace(s, "^0x"))
   Return, e
}
Last Edit: April 11, 2012, 10:44:54 PM by lnminente

jistme

  • Guest

Kyle4G

  • Newbie
  • *
  • Posts: 7