hjf

Sunday, May 22, 2016

Pixel Grabber (coordinate and pixel color info at mouse position - utility written in AHK)

Pixel Grabber V1.0



If you are a graphic designer then you may be familiar with ColorPic or Gpic; for those of you who aren't familiar with those programs (or other alternatives) these are color picker  and swatch programs (Gpic can convert PS .ase to GIMP .gpl and vice versa) that are great for retrieving color and some window info at the mouse cursor.

There are quite a few decent alternatives out there, but I wanted something more tailored to my needs since not only do I do graphic design, but I also build lots of GUI's in AutoHotkey and so I wrote a utility that is great for graphic design, but also good for building AHK GUI's.

Pixel Grabber V1.0 is a small utility that retrieves coordinate and color information at the mouse cursor simply by holding the Contol key and left clicking (Ctrl+Left Click). For now the information retrieved is the Windows title (not all windows have names), the Screen (Desktop) and Client  (if exists) coordinates relative to the each, and the actual pixels color with the code and a preview of the color. All information is copied to the clipboard in subsequent order, but the clipboards contents can be cleared with a button.

Downloads

Copyright Ian Pride 2016 © This program is distributed under the terms of the GNU General Public License.

Your choice of just the portable executable or the zip package which inludes the executable, source code, and a copy of the license:

Source Script (needs AHK, use the exe to use without install)

; Name:   Pixel Grabber V1.0 
; Author: Lateralus138 (A.K.A Flux Apex A.K.A Ian Pride)
; Year: 2016
; Copyright Ian Pride 2016 © This program is distributed under the terms of the GNU General Public License.
; Email: faithnomoread@yahoo.com
; http://www.gnu.org/licenses/gpl-3.0.en.html
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program.  If not, see .
;
; Gets window and color information at pixel coordinate 
; with the hotkeys: Ctrl+LeftClick. Very useful for 
; graphic design or writing AutoHotkey GUIs. 
; 
OnMessage(0x20, "WM_SETCURSOR")
#SingleInstance, Force
Menu, Tray, NoStandard
Menu, Tray, Add, &Help, gsHlp
Menu, Tray, Add, My &Blog, gsMBlg 
Menu, Tray, Add
Menu, Tray, Add, E&xit, gsExt
_fGtMn()
GuiControl, Show, gsRstClp %But%
Return
;End auto-execute

;Hotkeys
+Esc::Reload
^LButton::_fGtInf(_vX, _vY,_vRgb,_vBgr, _vWx, _vWy, _vWt, _vWw, _vWh, _vXc, _vYc)
;Gosubs
gsMBlg:
 Run, "http://agnosticmicrocosm.blogspot.com/"
Return
gsHlp:
 MsgBox,64,Pixel Grabber Help, % "To use this simply hold Ctrl & left click the place you"
  . "`nwant the coordinates & color of. Coordinates & color" 
  . "`nwill be displayed & copied to your clipboard. Multiple" 
  . "`ninfo boxes can be left open and subsequent new" 
  . "`ncoordinates & colors will be added to the clipboard" 
  . "`nstack."
Return
gsHide:
 Gui, Cancel
Return
MainGuiEscape:
 Gosub, gsHide
Return
gsRstClp:
 clipboard =
Return

;Functions
MouseOver(_vXa, _vYa, _vXb, _vYb)
{
 MouseGetPos, _vPx, _vPy
 _vDtct := _vPx >= _vXa AND _vPx <= _vXb AND _vPy >= _vYa AND _vPy <= _vYb
 Return _vDtct
}
WM_SETCURSOR(){
 Loop
  {
   If MouseOver(0, 0, 250, 344) {
    If Not hCursor1 { 
      hCursor1 := DllCall("LoadCursor", "uint", 0, "uint", 32512)
     }
    DllCall("SetCursor", "uint", hCursor1)
    ;Return True
   } 
   If MouseOver(135, 164, 247, 186) Or MouseOver(135, 190, 247, 212) Or MouseOver(135, 216, 247, 238) Or MouseOver(135, 242, 247, 264) {
    If Not hCursor2 { 
      hCursor2 := DllCall("LoadCursor", "uint", 0, "uint", 32649)
     }
    DllCall("SetCursor", "uint", hCursor2)
    Return True
   }
   GuiControl, Show, gsHlp %But%
   Break
  }
 Return
}
WM_SETCURSOR2(){
 Loop
  {
   IfWinActive, Pixel Grabber Info 
   {
    If MouseOver(20, 81, 66, 129) Or  MouseOver(256, 99, 290, 114) {
     If Not hCursor2 { ;Make sure the cursor is already loaded 
       hCursor2 := DllCall("LoadCursor", "uint", 0, "uint", 32649)
      }
     DllCall("SetCursor", "uint", hCursor2)
     Return True ;Stop further processing
    }  
   }
  }
 Return
}

_fGtInf(ByRef _vX, ByRef _vY, ByRef _vRgb, ByRef _vBgr, ByRef _vWx, ByRef _vWy, ByRef _vWt, ByRef _vWw, ByRef  _vWh, ByRef _vXc, ByRef _vYc){
 OnMessage(0x20, "WM_SETCURSOR2")
 CoordMode, Mouse, Screen
 MouseGetPos, _vX, _vY
 MouseGetPos,,,_vWPn
 WinActivate, ahk_id %_vWPn%
 CoordMode, Mouse, Window
 MouseGetPos, _vXc, _vYc
 WinGetActiveStats, _vWt, _vWw, _vWh, _vWx, _vWy
 If (_vWx = "-5"){
  _vWx := "0"
  _vXc := _vXc - 5
 }
 If (_vWy = "-5"){
  _vWy := "0"
  _vYc := _vYc - 5
 }
 CoordMode, Pixel, Screen
 PixelGetColor, _vRgb , %_vX%, %_vY%,RGB
 PixelGetColor, _vBgr , %_vX%, %_vY%
 clipboard := clipboard "`nWindow Name: `n" _vWt "`nDesktop Relative:`nx" _vX " y" _vY "`nWindow Relative: `nx" _vXc " y" _vYc "`nColor at coordinate: `n" _vRgb "`n"
 Gui, New
 Gui, Add, Text, w300+BackgroundTrans, % "Active Window Name:`n" 
  . _vWt
  . "`n`nWindow upper left starting position: `nx: "
  . _vWx "        |     y: " _vWy 
  . "`n`nDesktop relative coordinates at mouse position:`nx: " 
  . _vX "        |     y: " _vY 
  . "`n`nWindow relative coordinates at mouse position:`nx: " 
  . _vXc "        |     y:" _vYc 
  . "`n`nCoordinates and color have been copied to your clipboard." 
 Gui, Add, Progress, xp+5 yp+186 w50 h50 c%_vRgb%,100
 StringReplace, _vRgb, _vRgb, 0x,
 Gui, Add, Text, +BackgroundTrans xp+60 yp+18, % "Color at mouse postion: " . _vRgb
 Gui, Add, Button, xp+175 yp-2 ggsHide, Close
 Gui, Show,w300 ,Pixel Grabber Info
 Return
}
WM_MOUSELEAVE(){
}
_fGtMn(){

 OnMessage(0x20, "WM_SETCURSOR")
 Gui, New
 Gui, Main: Default
 Gui, Font, s8, Cambria
 _fGrphx("125","0","66","100","125","125","EF7D1A","2","2")
 _fGrphx("0","125","66","100","125","125","EF7D1A","2","2")
 _fGrphx("0","0","66","100","125","125","7DA485","2","2")
 _fTxtBrdr("Pixel","16","0","EF7D1A","white","28")
 _fTxtBrdr("Grabber","100","0","7DA485","white","28")
 Gui, Font, s11, Cambria
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y141  w112 h22, 100
 _fTxtBrdr2("Reset Clipboard","112","22", "gsRstClp","135","141","7DA485","White","11")
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y167  w112 h22, 100
 _fTxtBrdr2("Help","112","22","gsHlp","135","167","7DA485","White","11")
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y193  w112 h22, 100
 _fTxtBrdr2("My Blog","112","22","gsMBlg","135","193","7DA485","White","11")
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y219  w112 h22, 100
 _fTxtBrdr2("Exit","112","22","gsExt","135","219","7DA485","White","11")
 Gui, Main: Show, w250 h250 Center, Pixel Grabber
 Return
}
_fGrphx(_vCntrX, _vCntrY, _vLp, _vLpWdth, _vWdth, _vHght, _vClr, _vIncrA, _vIncrB, _vBgClrb := "White"){
 Loop, %_vLp%
  { 
   Gui, Main: Add, Progress, -Smooth Disabled x%_vCntrX% y%_vCntrY% w%_vWdth% h%_vHght% Background%_vBgClrb% c%_vClr%, % _vLpWdth
   _vCntrX := _vCntrX + _vIncrA
   _vCntrY := _vCntrY + _vIncrB
  }
 Return
}
_fTxtBrdr(_vTxt, _vXb := "0", _vYb := "0", _vBgClr := "Black", _vClr := "White", _vTxtSz := "8"){
 Gui, Font, q5 s%_vTxtSz%, Cambria
 Gui, Main: Add, Text, +BackgroundTrans x%_vXb% y%_vYb% c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp yp+2 c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp+2 yp c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp yp-2 c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp-1 yp+1 c%_vClr%, % _vTxt
 Return
}
_fTxtBrdr2(_vTxt2, _vXw, _vYw, _vGs, _vXb2 := "0", _vYb2 := "0", _vBgClr2 := "Black", _vClr2 := "White", _vTxtSz2 := "8"){
 Gui, Font, q5 s%_vTxtSz2%, Cambria
 Gui, Main: Add, Text, +Center +BackgroundTrans x%_vXb2% y%_vYb2% w%_vXw% h%_vYw% c%_vBgClr2%, %_vTxt2%
 Gui, Main: Add, Text, +Center +BackgroundTrans xp yp+2 w%_vXw% h%_vYw% c%_vBgClr2%, % _vTxt2
 Gui, Main: Add, Text, +Center +BackgroundTrans xp+2 yp w%_vXw% h%_vYw% c%_vBgClr2%, % _vTxt2
 Gui, Main: Add, Text, +Center +BackgroundTrans xp yp-2 w%_vXw% h%_vYw% c%_vBgClr2%, % _vTxt2
 Gui, Main: Add, Text, +Center +BackgroundTrans xp-1 yp+1 w%_vXw% h%_vYw% c%_vClr2% g%_vGs%, % _vTxt2
 Return
}
GuiClose:
 Gui, Cancel
Return
gsExt:
MainGuiClose:
 SplashTextOn, 200, 22, ,% "Exiting Pixel Grabber!!!"
 Sleep 1500
 ExitApp
 
 

No comments: