4月192017
AU3键盘HOOK
#include <WindowsConstants.au3>
;Global Const $tagKBDLLHOOKSTRUCT = "dword vkCode;dword scanCode;dword flags;dword time;ulong_ptr dwExtraInfo"
Global $hCallback = DllCallbackRegister("LowLevelKeyboardProc", "long", "int;wparam;lparam")
Global $hModule = _WinAPI_GetModuleHandle(0)
Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hCallback), $hModule)
OnAutoItExitRegister("OnAutoItExit")
While 1
Sleep(10)
WEnd
;===========================================================
;nCode
;小于0返回CallNextHookEx
;wParam
;消息: WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
;lParam
;KBDLLHOOKSTRUCT结构指针
;Return
;如果钩子过程没有处理消息,返回CallNextHookEx
;如果钩子过程处理的消息,返回一个非零值来防止系统传递消息给其余的钩链或目标窗口
;===========================================================
Func LowLevelKeyboardProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
Local $iCode = DllStructGetData($tKEYHOOKS, "vkCode")
Local $iScan = DllStructGetData($tKEYHOOKS, "scanCode")
Local $iFlag = DllStructGetData($tKEYHOOKS, "flags")
Switch $wParam
Case $WM_KEYDOWN
ToolTip("按键按下: (" & $iCode & ")")
If $iCode = 65 Then Return 1;屏蔽a键按下
Case $WM_KEYUP
ToolTip("按键抬起: (" & $iCode & ")")
Case $WM_SYSKEYDOWN
ToolTip("系统按键按下: (" & $iCode & ")")
Case $WM_SYSKEYUP
ToolTip("系统按键抬起: (" & $iCode & ")")
Case Else
ConsoleWrite($wParam & @CRLF)
ToolTip("其他消息: (" & $wParam & ")")
EndSwitch
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc
Func OnAutoItExit()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hCallback)
EndFunc ;==>OnAutoItExit```
<br />
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!