; WH_MOUSE_LL := 14 ;全局鼠标钩子常数 ; WH_KEYBOARD_LL := 13 ;全局键盘钩子常数 SetBatchLines, -1 Gosub, 鼠标钩子 LowLevelMouseProc(nCode, wParam, lParam) { ToolTip, 鼠标操作时触发 Global MouseHook := "" SetTimer, 鼠标钩子, -1000 } 鼠标钩子: MouseHook := new WindowsHook(WH_MOUSE_LL := 14, "LowLevelMouseProc") Return F1:: SetTimer, 鼠标钩子, Off ToolTip Return ;==================== 下面是类函数库 ==================== class WindowsHook { __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") } } /* ; 另一个独立的调用方法,不带清空关闭的例子 MouseHook := DllCall("SetWindowsHookEx", "int", WH_MOUSE := 14, "uint", RegisterCallback("MouseProc"), "uint", 0, "uint", 0) Loop { Sleep, 10 MouseGetPos, x, y ToolTip, 主线程持续运算演示-%A_Index%, x+10,y-30 } ;效果是:移动鼠标不断激活 MouseProc(nCode, wParam, lParam) { ToolTip, 移动鼠标时触发 } Esc::ExitApp */
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)