Experimenting with finding average color of a given region

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scripts
Posts: 8
Joined: 12 Dec 2013, 21:35

Experimenting with finding average color of a given region

06 Feb 2014, 04:40

I'm very interested in the function RegionGetColor discussed in this old thread. But I can't make the demonstration code on the page work so I can learn how to use it. I've copied and pasted it into the SciTE4 editor, but when I run it, I get a "call to nonexistent function" error on line 68, which is "Color1 := regionGetColor(GuiX, GuiY, GuiW, GuiH) ;get the color of the region". Apparently it was working just fine for others. Can someone help me figure out what I'm doing wrong? This is the code in question, which was originally posted by infogulch on the other AHK forum. Thanks!

Code: Select all

 ;region ;AutoExec; #######################################################################
#NoEnv
#SingleInstance, Force
CoordMode, Mouse, Screen
RegionMain:
If !regionInit
{
   OnExit, Exit
   Gui, 1:+AlwaysOnTop +ToolWindow
   Gui, 1:Color, 0xffffff
   Gui, 1:Add, Edit, vGuiTextVar +ReadOnly h160 w180, Color: 0xffffff`nCount: `nTime: `n`n`n`n`n`n`n
   Gui, 1:Show, , regionColor
   Gui, 2:Color, 0xCCCCCC
   Gui, 2:+ToolWindow -Caption +Border +AlwaysOnTop +0x20 ; 0x20=click-thru
   Gui, 2:Add, Text, vGuiTextVar2 w80
   Gui, 2:+LastFound
   2GuiID := WinExist()
   Gui, 2:Show, X-2000 Y-2000 W1 H1
   WinSet, Trans, 150, ahk_id %2GuiID%
;   CoordMode, Mouse, Screen
   Process, Priority,, High
   SetBatchLines, -1
   SetWinDelay, -1
   RegionInit = 1
   GuiX := GuiY := 0
   GuiW := GuiH := 100
}
Gui, 1:Show
return
;end_region

;region ;Labels and Hotkeys; #############################################################
Esc::
Exit:
GuiClose:
   ExitApp

!LButton::
; use gui 2 to create a rectangle for area selection
   If !RegionInit
      GoSub RegionMain
   MouseGetPos, s_MSX, s_MSY, s_ID, s_CID, 2 ;start mouse X and Y
   WinSet, AlwaysOnTop, On, ahk_id %2GuiID%
   Loop
   {
      Sleep 20
      If !GetKeyState("LButton", "P")                  ;break if user releases the mouse
         Break   
      MouseGetPos, c_MSX, c_MSY                     ;current mouse X and Y
      GuiX := (s_MSX < c_MSX ? s_MSX : c_MSX)            ;use whichever smaller for X and Y
      GuiY := (s_MSY < c_MSY ? s_MSY : c_MSY)
      GuiW := Abs(Abs(s_MSX)-Abs(c_MSX))               ;doesn't matter which is bigger,
      GuiH := Abs(Abs(s_MSY)-Abs(c_MSY))               ;the absloute difference will be the same
      WinMove, ahk_id %2GuiID%,, GuiX, GuiY, GuiW, GuiH   ;move the window there
      GuiControl, 2:, GuiTextVar2, % GuiW ", " GuiH
   }
^!+r::               ;to retry at the last used coord.
   WinMove, ahk_id %2GuiID%,, GuiX, GuiY, GuiW, GuiH      ;to see where it's retrying
   Sleep 100
   WinMove, ahk_id %2GuiID%,, -2000,-2000, 2, 2          ;hide the window away
      WinGetPos, WinX, WinY, WinW, WinH, ahk_id %s_ID%
      ControlGetPos, CtrX, CtrY, CtrW, CtrH, , ahk_id %s_CID%
      regionInfo := "Relative to:`n   Screen: " GuiX "," GuiY
      regionInfo .= "`n   Window: " GuiX-WinX "," GuiY-WinY
      regionInfo .= "`n   Control: " GuiX-WinX-CtrX "," Guiy-WinY-CtrY
      regionInfo .= "`nWidth/Height: " GuiW "," GuiH
   Info1 := "RGB:`t"
   Color1 := regionGetColor(GuiX, GuiY, GuiW, GuiH) ;get the color of the region
   Time1 := "Time: " ErrorLevel
   Gui, 1:Color, %Color1%
   GuiControl, , GuiTextVar, % Info1 Color1 "`n`t" Time1 "`n`n" regionInfo
return
;end_region 
User avatar
LazyMan
Posts: 26
Joined: 14 Jan 2014, 00:22
Location: peering out from behind my favorite rock

Re: Experimenting with finding average color of a given regi

07 Feb 2014, 17:21

The code you need is in the first post of link you provided in the section labeled {Code}.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Darkmaster006, haomingchen1998 and 190 guests