|
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $i = 0
Global $hHook, $hStub_KeyProc, $buf = "", $title = "", $title_1 = "", $keycode, $buffer = "", $nMsg
Global $hStub_MouProc,$hHook_mouse,$_whook
Local $hmod
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hStub_MouProc = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
$hHook_mouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
$_whook=_WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($hStub_MouProc),$hmod)
While 1
Sleep(1)
If $i> 5 Then ConsoleWrite($i&@CR)
WEnd
Func _Mouse_Events_Handler($wnCode, $wwParam, $wlParam)
Switch $wwParam
Case $WM_LBUTTONUP ;按下鼠标左键
;MsgBox(1,1,"按下鼠标左键")
;Return 1
Return _WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam)
Case $WM_RBUTTONUP ;按下鼠标左键 WM_MBUTTONDBLCLK WM_MBUTTONDOWN
;MsgBox(1,1,"按下鼠标右键")
Return 1
;_WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam)
EndSwitch
Return _WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam) ;消息传递到下一个钩子
EndFunc
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 _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
$i= $i+1;
Return 1
ElseIf ($wParam = $WM_KEYUP) Then
ToolTip("{win} was released.")
$i = 0;
EndIf
EndIf
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func _exit()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
Exit
EndFunc ;==>_exit |
|