本帖最后由 pusofalse 于 2010-2-10 01:37 编辑
7#的代码在截取到{win}键之后,只是显式的弹出一个Msgbox窗口通知用户已经截取到按键,并没有阻止这个消息的继续传递,将Msgbox去掉,改成你希望的代码并加一句Return 1试下:#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
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndIf
If $wParam = $WM_KEYDOWN Then
If $wParam = 256 Then
ToolTip("{win} was pressed.")
Return 1
EndIf
Else
Local $flags = DllStructGetData($tKEYHOOKS, "flags")
Switch $flags
Case $LLKHF_ALTDOWN
MsgBox(0, "", "拦截")
EndSwitch
EndIf
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func _exit()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
Exit
EndFunc ;==>_exit
以上代码有误,正确应该如下:#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
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
|