name22

Catch Doubleclicks using LowLevel Hook

Oct 31st, 2013
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WindowsConstants.au3>
  2. #include <WinAPI.au3>
  3.  
  4. ;Catches Doubleclicks without letting them reach any other processes besides this script.
  5. ;Unfortunately the delay for normal clicks cannot be prevented due to this design.
  6.  
  7. ; -Author: name22 (www.autoit.de)
  8.  
  9. Global Const $iDoubleclickTime = 150
  10. Global $hCallback, $hMod, $hHook, $iClickState = 0
  11.  
  12. OnAutoItExitRegister("_Shutdown")
  13. HotKeySet("{ESC}", "_Exit")
  14.  
  15. $hCallback = DllCallbackRegister("_LL_MouseProc", "long", "int;wparam;lparam")
  16.  
  17. $hMod = _WinAPI_GetModuleHandle(0)
  18. $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hCallback), $hMod)
  19.  
  20. While Sleep(1000)
  21. WEnd
  22.  
  23. Func _LL_MouseProc($nCode, $wParam, $lParam)
  24.     If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
  25.  
  26.     Switch $wParam
  27.         Case $WM_LBUTTONDOWN
  28.             Switch $iClickState
  29.                 Case 0
  30.                     AdlibRegister("_DelayMouseClick", $iDoubleclickTime)
  31.                     $iClickState = 1
  32.                     Return 1
  33.                 Case 1
  34.                     AdlibUnRegister("_DelayMouseClick")
  35.                     $iClickState = 0
  36.                     ConsoleWrite("Doubleclick!" & @CRLF)
  37.                     Return 1
  38.                 Case 2
  39.                     $iClickState = 0
  40.             EndSwitch
  41.     EndSwitch
  42.     Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
  43. EndFunc
  44.  
  45. Func _DelayMouseClick()
  46.     $iClickState = 2
  47.     MouseClick("left")
  48.     AdlibUnRegister("_DelayMouseClick")
  49. EndFunc
  50.  
  51.  
  52. Func _Exit()
  53.     Exit
  54. EndFunc
  55.  
  56. Func _Shutdown()
  57.     Do
  58.         Sleep(20)
  59.     Until $iClickState = 0
  60.  
  61.     _WinAPI_UnhookWindowsHookEx($hHook)
  62.     DllCallbackFree($hCallback)
  63. EndFunc
RAW Paste Data