; MouseMove移动也能识别,此API每移动1个像素就会回调1次函数,容易阻塞线程影响脚本运行
#Persistent
Hook := new WindowsHook(WH_MOUSE_LL := 14, "LowLevelMouseProc")

LowLevelMouseProc(nCode, wParam, lParam) {
  static WM_MOUSEMOVE := 0x200
  if (wParam = WM_MOUSEMOVE)
    SetTimer, MouseStop, -100  ; 悬停100毫秒时,提示
}

MouseStop() {
  SoundBeep
  ToolTip 鼠标已经停止!
}

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")
  }
}

F1::Hook := ""  ; 关闭释放回调函数

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。