以下上P版的代码,能拦截WIN键。试过改键值,但不能拦截CTRL,ALT这些键。。是不是还要经过其它特殊处理?#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $hHook, $hStub_KeyProc, $buf = "", $title = "", $title_1 = "", $keycode, $buffer = "", $nMsg
Local $hmod
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
While 1
Sleep(1)
WEnd
Func _KeyProc($nCode, $wParam, $lParam)
Local $tKEYHOOKS, $wVKey
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndIf
$wVKey = DllStructGetData($tKEYHOOKS, "vkCode")
If ($wVKey = 91) Then ;这里用的是asi2码
If ($wParam = $WM_KEYDOWN) Then
ToolTip("{win} was pressed.")
Return 1
ElseIf ($wParam = $WM_KEYUP) Then
ToolTip("{win} was released.")
EndIf
EndIf
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func _exit()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
Exit
EndFunc ;==>_exit
|