Code: Select all
SetWinDelay, 0
SetBatchLines, -1
!f::SetTimer, Green, -10
Green:
Diameter := 15, Thickness := 2, Right := 10 ;Offset to the right
SetTimer, FFA500, -12000 ;Orange
SetTimer, Red, -18000
Red:
FFA500: ;Orange
WinClose, ahk_id %hCircle%
hCircle := MakeCircle(A_ThisLabel, Diameter, Thickness)
Hook := new WindowsHook(WH_MOUSE_LL := 14, "LowLevelMouseProc", hCircle)
CoordMode, Mouse
MouseGetPos, x, y
WinMove, ahk_id %hCircle% ,, Right + x - offset:=Diameter//2, y - offset
Return
LowLevelMouseProc(nCode, wParam, lParam)
{ ;teadrinker
global offset, Right
static WM_MOUSEMOVE := 0x200
if (wParam = WM_MOUSEMOVE)
{
mouse_x := NumGet(lParam + 0, "Int") + Right
mouse_y := NumGet(lParam + 4, "Int")
WinMove, ahk_id %A_EventInfo% ,, mouse_x - offset, mouse_y - offset
}
Return DllCall("CallNextHookEx", "Ptr", 0, "Int", nCode, "UInt", wParam, "Ptr", lParam)
}
class WindowsHook
{ ;teadrinker
__New(type, callback, eventInfo := "", isGlobal := true)
{
this.pCallback := RegisterCallback(callback, "Fast", 3, eventInfo)
this.hHook := DllCall("SetWindowsHookEx", "Int", type, "Ptr", this.pCallback
, "Ptr", !isGlobal ? 0 : DllCall("GetModuleHandle", "UInt", 0, "Ptr")
, "UInt", isGlobal ? 0 : DllCall("GetCurrentThreadId"), "Ptr")
}
__Delete()
{
DllCall("UnhookWindowsHookEx", "Ptr", this.hHook)
DllCall("GlobalFree", "Ptr", this.pCallback, "Ptr")
}
}
MakeCircle(color, Diameter := 100, thickness := 10, transparency := 255)
{ ; https://autohotkey.com/board/topic/7377-create-a-transparent-circle-in-window-w-winset-region/
Gui New, +E0x20 +AlwaysOnTop +HwndhCircle +ToolWindow -Caption
outer := DllCall("CreateEllipticRgn", "Int", 0, "Int", 0, "Int", Diameter, "Int", Diameter)
inner := DllCall("CreateEllipticRgn", "Int", thickness, "Int", thickness, "Int"
, Diameter - thickness, "Int", Diameter - thickness)
DllCall("CombineRgn", "UInt", outer, "UInt", outer, "UInt", inner, "Int", 3) ; RGN_XOR = 3
DllCall("SetWindowRgn", "UInt", hCircle, "UInt", outer, "UInt", true)
Gui Color,% color
Gui Show, xCenter yCenter w%Diameter% h%Diameter% NoActivate
WinSet Transparent,% transparency, ahk_id %Circle%
Return, hCircle
}