[已解决]求一个鼠标拦截钩子源码
本帖最后由 kxing 于 2010-9-8 22:49 编辑我得到过 xsjtxy 这位好心人给了这段代码,但是只能监测到有鼠标点击操作,我希望在监测到的同时也能拦截此动作,不让鼠标真点击。
只能监测不能拦截的代码如下:#Include <WinAPI.au3>
#include <WindowsConstants.au3>
While 1
Global $_endmouse=""
$_whand = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
$_whmod = _WinAPI_GetModuleHandle(0)
$_whook=_WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($_whand),$_whmod)
$mouse = _waitmouse()
Switch $mouse
Case 1
MsgBox(64,"","按下鼠标左键")
Case 2
MsgBox(64,"","按下鼠标右键")
Case 3
MsgBox(64,"","按下鼠标中键")
Case 4
MsgBox(64,"","鼠标轮转动")
EndSwitch
WEnd
Func _waitmouse()
While 1
Sleep(1)
If Not $_endmouse="" Then
_WinAPI_UnhookWindowsHookEx($_whook)
DllCallbackFree($_whand)
Return $_endmouse
EndIf
WEnd
EndFunc
Func _Mouse_Events_Handler($wnCode, $wwParam, $wlParam)
Switch $wwParam
Case $WM_LBUTTONUP ;按下鼠标左键
$_endmouse = 1
Case $WM_RBUTTONDOWN ;按下鼠标右键
$_endmouse = 2
Case $WM_MBUTTONDOWN ;按下鼠标中键
$_endmouse = 3
Case $WM_MOUSEWHEEL ;鼠标轮转动
$_endmouse = 4
EndSwitch
EndFunc比如说我在一个确定按钮上点击了鼠标左键,那么这时候程序就提示我已按下鼠标左键,但是这个确定按钮依然存在,鼠标并没有进行对他点击动作。
可能写的有点罗索,但是希望帮助我的人能看懂,先多谢了!!!! 有人能帮助下吗,高手来啊!!! 看来没办法了,高手没看到,自己顶起来! #Include <WinAPI.au3>
#include <WindowsConstants.au3>
OnAutoItExitRegister("OnAutoItExit")
$_whand = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
$_whmod = _WinAPI_GetModuleHandle(0)
$_whook=_WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($_whand),$_whmod)
While 1
Sleep(1)
WEnd
Func _Mouse_Events_Handler($wnCode, $wwParam, $wlParam)
If $wnCode < 0 Then
Return _WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam) ;消息传递到下一个钩子
EndIf
Switch $wwParam
Case $WM_LBUTTONUP ;按下鼠标左键
Return 1
Case $WM_RBUTTONDOWN ;按下鼠标右键
Return 1
Case $WM_MBUTTONDOWN ;按下鼠标中键
Return 1
Case $WM_MOUSEWHEEL ;鼠标轮转动
Return 1
EndSwitch
EndFunc
Func OnAutoItExit() ;退出时卸载钩子
_WinAPI_UnhookWindowsHookEx($_whook)
DllCallbackFree($_whand)
EndFunc ;==>OnAutoItExit 嗯,多谢ls了。
似乎有点不太稳定。。。
页:
[1]