8月32015
简单获取鼠标动作UDF
#Include <WinAPI.au3>
#include <WindowsConstants.au3>
;=====说明============================================================================
; _Waitmouse 返回用户的mouse按键码
; 用法: 脚本运行到这一行会暂停,当用户按下mouse键后继续执行,并且返回mouse按键码
; 例子:
; #include "waitmouse.au3"
; $mousekey = _waitmouse()
; If $mousekey=1 Then MsgBox(0,"你按的是","左键")
#cs=mouse按键码=========================================================================
Case $WM_LBUTTONUP ;按下鼠标左键
$_endmouse = 1
Case $WM_RBUTTONDOWN ;按下鼠标右键
$_endmouse = 2
Case $WM_MBUTTONDOWN ;按下鼠标中键
$_endmouse = 3
Case $WM_MOUSEWHEEL ;鼠标轮转动
$_endmouse = 4
#ce===================================================================================
;准备工作,安装钩子===========================================================
Global $_endmouse=""
;创建一个回调函数
$_whand = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
;返回回调函数句柄
$_whmod = _WinAPI_GetModuleHandle(0)
;安装钩子
;_WinAPI_SetWindowsHookEx(钩子类型,指针,回调函数句柄)
$_whook=_WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($_whand),$_whmod)
;准备完成=====================================================================
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
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!