本帖最后由 afan 于 2019-6-18 22:06 编辑
刚写的,XP测试ok,其它未测~#include <WinAPI.au3>
OnAutoItExitRegister('_Exit')
Opt('GUIOnEventMode', 1)
Global $h_Key_Proc = DllCallbackRegister('_Key_Proc', 'long', 'int;wparam;lparam')
Global $h_Hook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($h_Key_Proc), _WinAPI_GetModuleHandle(0))
GUICreate('判断大小键盘回车键', 300, 200)
GUISetOnEvent(-3, '_Exit')
Global $iLb_Tip = GUICtrlCreateLabel('请按回车键测试', 50, 80, 200, 20)
GUISetState()
While 1
Sleep(1000)
WEnd
Func _Key_Proc($nCode, $wParam, $lParam)
Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($h_Hook, $nCode, $wParam, $lParam)
If DllStructGetData($tKEYHOOKS, 'vkCode') = 13 Then
Switch DllStructGetData($tKEYHOOKS, 'flags')
Case 0
GUICtrlSetData($iLb_Tip, '主键盘回车键按下')
Case 1
GUICtrlSetData($iLb_Tip, '小键盘回车键按下')
Case 0x80
GUICtrlSetData($iLb_Tip, '主键盘回车键弹起')
Case 0x81
GUICtrlSetData($iLb_Tip, '小键盘回车键弹起')
EndSwitch
EndIf
Return _WinAPI_CallNextHookEx($h_Hook, $nCode, $wParam, $lParam)
EndFunc ;==>_Key_Proc
Func _Exit()
_WinAPI_UnhookWindowsHookEx($h_Hook)
DllCallbackFree($h_Key_Proc)
Exit
EndFunc ;==>_Exit
|