4月192017
AU3鼠标HOOK
#include <WindowsConstants.au3>
;typedef struct tagMSLLHOOKSTRUCT {
; POINT pt;
; DWORD mouseData;
; DWORD flags;
; DWORD time;
; ULONG_PTR dwExtraInfo;
;}MSLLHOOKSTRUCT, *PMSLLHOOKSTRUCT, *LPMSLLHOOKSTRUCT;
;typedef struct tagPOINT {
; LONG x;
; LONG y;
;} POINT, *PPOINT;
Global Const $tagMSLLHOOKSTRUCT = "long x;long y;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global $hCallback = DllCallbackRegister("LowLevelMouseProc", "long", "int;wparam;lparam")
Global $hModule = _WinAPI_GetModuleHandle(0)
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hCallback), $hModule)
OnAutoItExitRegister("OnAutoItExit")
While 1
Sleep(10)
WEnd
;===========================================================
;nCode
;小于0返回CallNextHookEx
;wParam
;消息: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN, WM_RBUTTONUP
;lParam
;MSLLHOOKSTRUCT结构指针
;Return
;如果钩子过程没有处理消息,返回CallNextHookEx
;如果钩子过程处理的消息,返回一个非零值来防止系统传递消息给其余的钩链或目标窗口
;===========================================================
Func LowLevelMouseProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
Local $tMSLLHOOKS = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)
Local $iX = DllStructGetData($tMSLLHOOKS, "x")
Local $iY = DllStructGetData($tMSLLHOOKS, "y")
Local $iData = DllStructGetData($tMSLLHOOKS, "mouseData")
Local $iH = _WinAPI_HiWord($iData)
Local $iL = _WinAPI_LoWord($iData)
Switch $wParam
Case $WM_MOUSEMOVE
ToolTip("鼠标移动: (" & $iX & "," & $iY & ")")
Case $WM_LBUTTONDOWN
ToolTip("鼠标左键按下: (" & $iX & "," & $iY & ")")
Case $WM_LBUTTONUP
ToolTip("鼠标左键抬起: (" & $iX & "," & $iY & ")")
Case $WM_RBUTTONDOWN
ToolTip("鼠标右键按下: (" & $iX & "," & $iY & ")")
Case $WM_RBUTTONUP
ToolTip("鼠标右键抬起: (" & $iX & "," & $iY & ")")
Return 1;屏蔽鼠标右键弹起,内部处理消息
Case $WM_MBUTTONDOWN
ToolTip("鼠标滚轮按下: (" & $iX & "," & $iY & ")")
Case $WM_MBUTTONUP
ToolTip("鼠标滚轮抬起: (" & $iX & "," & $iY & ")")
Case $WM_MOUSEWHEEL
If $iH > 0 Then
ToolTip("鼠标滚轮上滚: (" & $iX & "," & $iY & ")")
Else
ToolTip("鼠标滚轮下滚: (" & $iX & "," & $iY & ")")
EndIf
Case Else
ConsoleWrite($wParam & @CRLF)
ToolTip("其他消息: (" & $wParam & ")")
EndSwitch
Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam)
EndFunc ;==>_MouseProc
Func OnAutoItExit()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hCallback)
EndFunc ;==>OnAutoItExit```
<br />
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!