移动鼠标或按下键盘的键时,弹出窗口
比如,移动鼠标 或 按下键盘的键时,弹出窗口 #include <WinAPI.au3>#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
HotKeySet("^{end}",'_exit')
Global $hHook, $hStub_KeyProc
Global $hStub_MouProc,$hHook_mouse
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_MouProc),$hmod)
While 1
Sleep(10)
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 ($wParam = $WM_KEYDOWN) Then
ToolTip(''&$wVKey&''&" was pressed.")
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ;不加这一句可以截断按下动作传递
Return 1
ElseIf ($wParam = $WM_KEYUP) Then
ToolTip(''&$wVKey&''&" was released.")
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ;不加这一句可以截断弹起动作传递
EndIf
EndFunc ;==>_KeyProc
Func _Mouse_Events_Handler($wnCode, $wwParam, $wlParam)
Switch $wwParam
Case $WM_LBUTTONUP ;弹起鼠标左键
ToolTip('L UP.')
Case $WM_LBUTTONDOWN ;按下鼠标左键
ToolTip('L DOWN.')
Case $WM_RBUTTONUP ;弹起鼠标右键
ToolTip('R UP.')
Case $WM_RBUTTONDOWN ;按下鼠标右键
ToolTip('R DOWN.')
EndSwitch
;Return _WinAPI_CallNextHookEx($hHook_mouse, $wnCode, $wwParam, $wlParam) ;与按键相同,不加这一句可以阻断鼠标动作传递,但是实际测试没有效果,都不能阻断
EndFunc
Func _exit()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
Exit
EndFunc ;==>_exit
用钩子函数,可以实现的 谢谢分享!~
页:
[1]