2) Allow click-and-drag to select the region to record instead of constantly showing GifCam window ontop
Anyway, I made an AHK to solve 1) and 2) above. usage:
Code: Select all
#SingleInstance force
;#notrayicon ;Don't wanna see Autohotkey's icon in tray? Then uncomment this line
#NoEnv
#IfWinExist, ahk_class TGifCamForm
^+LButton::
SysGet, xborder, 32
SysGet, yborder, 33
SysGet, caption, 4
ControlGetPos, X, Y, ButtonWidth, ButtonHeight, TButton3, ahk_class TGifCamForm
DefineRegion("LButton", "Screen", left_x, right_x, top_y, bottom_y, region_width, region_height) ;Only need to supply 2 parameters "Trigger" (which key to stop DefineRegion) and "Mode" (result is relative to window or screen or client); then the function return the other 6 parameters, left_x, right_x, top_y, bottom_y, region_width, region_height, which is ready-to-use
GifCamX := left_x - xborder
GifCamY := top_y - yborder - caption
GifCamWidth := region_width + ButtonWidth + xborder * 2 + 10
GifCamHeight := region_height + yborder * 2 + caption
WinMove, ahk_class TGifCamForm, , %GifCamX%, %GifCamY%, %GifCamWidth%, %GifCamHeight%
return
!+p::
ControlSend, TButton4, {Enter}, ahk_class TGifCamForm
WinGet, ExStyle, ExStyle, ahk_class TGifCamForm
if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
{
Winset, AlwaysonTop, Off, ahk_class TGifCamForm
Winminimize, ahk_class TGifCamForm
Loop, 4
{
Gui, %A_Index%: -Caption +ToolWindow +ToolWindow +AlwaysOnTop
Gui, %A_Index%: Color, Green ;can state any Hex code i.e: 0x00ff
}
Gui, 1: show, % "x" left_x " y" top_y " w" region_width " h1 NoActivate"
Gui, 2: show, % "x" left_x " y" top_y " w1" " h" region_height " NoActivate"
Gui, 3: show, % "x" left_x " y" bottom_y " w" region_width " h1 NoActivate"
Gui, 4: show, % "x" right_x " y" top_y " w1" " h" region_height " NoActivate"
TrayTip, ,Recording...
sleep 2000
TrayTip,
}
Else
{
Loop, 4
Gui, %A_Index%: hide
Winset, AlwaysonTop, On, ahk_class TGifCamForm
Winrestore, ahk_class TGifCamForm
TrayTip, ,Stop recording
sleep 2000
TrayTip,
}
return
DefineRegion(Trigger, Mode, ByRef left_x, ByRef right_x, ByRef top_y, ByRef bottom_y, ByRef region_width, ByRef region_height) ;ByRef means the variable will be returned to caller with the same variable name
{
CoordMode, Mouse, %Mode% ; relative to window or screen or client (window title bar, menu and borders)
MouseGetPos, start_x, start_y ; start position of mouse
Loop, 4 ;Create 4 lines of a selection rectangle (display as 4 GUI)
{
Gui, %A_Index%: -Caption +ToolWindow +ToolWindow +AlwaysOnTop
Gui, %A_Index%: Color, Green ;can state any Hex code i.e: 0x00ff
}
Loop ;Can use settimer to reduce cpu usage (although less smooth)
{
MouseGetPos, start_x_2, start_y_2
If (start_x_2 > start_x) ;Update the selection rectangle
{
Gui, 1: Show, % "x" start_x " y" start_y " w" start_x_2 - start_x " h1 NoActivate"
Gui, 4: Show, % "x" start_x " y" start_y_2 " w" start_x_2 - start_x " h1 NoActivate"
}
Else
{
Gui, 1: Show, % "x" start_x_2 " y" start_y " w" start_x - start_x_2 " h1 NoActivate"
Gui, 4: Show, % "x" start_x_2 " y" start_y_2 " w" start_x - start_x_2 " h1 NoActivate"
}
If (start_y_2 > start_y)
{
Gui, 2: Show, % "x" start_x " y" start_y " w1 h" start_y_2 - start_y " NoActivate"
Gui, 3: Show, % "x" start_x_2 " y" start_y " w1 h" start_y_2 - start_y " NoActivate"
}
Else
{
Gui, 2: Show, % "x" start_x_2 " y" start_y_2 " w1 h" start_y - start_y_2 " NoActivate"
Gui, 3: Show, % "x" start_x " y" start_y_2 " w1 h" start_y - start_y_2 " NoActivate"
}
ToolTip, % "Width: " start_x_2 - start_x " - Height: " start_y_2 - start_y
;ToolTip, % GetOCR(left_x, top_y, region_width, region_height)
If (GetKeyState(Trigger, "P") = 0 ) ;Trigger (i.e: Left mouse) is Physically up
{
MouseGetPos, end_x, end_y
ToolTip
Loop, 4
Gui, %A_Index%: Hide
break
}
}
left_x := MinMaxAvg("min", start_x, end_x)
right_x := MinMaxAvg("max", start_x, end_x)
top_y := MinMaxAvg("min", start_y, end_y)
bottom_y := MinMaxAvg("max", start_y, end_y)
region_width := right_x - left_x
region_height := bottom_y - top_y
Return ;End of Define Region
}