Code: Select all
mouse_move_mh:=new mouseHook("mouse_move")
mouse_move_mh.hook()
capslock_mh:=new mouseHook("capslock_mouse_move")
ctrl_alt_shift_mh:=new mouseHook("ctrl_alt_shift_mouse_move")
~*Capslock up::capslock_mh.unhook() ; Turns off the hook unconditionally
~*shift up::ctrl_alt_shift_mh.unhook()
#IfWinActive, ahk_exe notepad.exe
Capslock::capslock_mh.hook() ; Turn on the hook in notepad, with capslock
^!Shift::ctrl_alt_shift_mh.hook()
#if
mouse_move(h,x,y){
IfWinActive ahk_exe notepad.exe
ToolTip, % "Mouse moved at " x " " y " in notepad",0,0,1
}
ctrl_alt_shift_mouse_move(h,x,y){
ToolTip, % "Mouse moved at " x " " y " while holding ctrl+alt+shift",0,25,2
}
capslock_mouse_move(h,x,y){
ToolTip, % "Mouse moved at " x " " y " while holding CapsLock",0,50,4
}
class mouseHook{
; User methods
hook(){
if !this.hHook
this.hHook:=DllCall("User32.dll\SetWindowsHookEx", "Int", 14, "Uint", this.regCallBack:=RegisterCallback(this.LowLevelMouseProc,"F",4, &this), "Uint", 0, "Uint", 0, "Ptr")
return
}
unHook(){
if this.hHook
DllCall("User32.dll\UnhookWindowsHookEx", "Uint", this.hHook)
return this.hHook:=""
}
; Internal methods.
__new(callbackFunc){
this.callbackFunc:=callbackFunc
}
LowLevelMouseProc(args*) {
; (nCode, wParam, lParam)
Critical
this:=Object(A_EventInfo),nCode:=NumGet(args-A_PtrSize,"Int"), wParam:=NumGet(args+0,0,"Ptr"), lParam:=NumGet(args+0,A_PtrSize,"UPtr")
x:=NumGet(lParam+0,0,"Int"),y:=NumGet(lParam+0,4,"Int"),flags:=NumGet(lParam+0,12,"UInt")
tf:=Func(this.callbackFunc).Bind(flags,x,y)
SetTimer, % tf, -0
return DllCall("User32.dll\CallNextHookEx","Uint",0, "Int", nCode,"Uint", wParam,"Uint",lParam)
}
__Delete(){
this.unHook()
if this.regCallBack
DllCall("GlobalFree", "Ptr", this.regCallBack)
return
}
}
esc::exitapp