【 tulaoshi.com - 编程语言 】
前边谈了模拟键盘,下面说说模拟鼠标。
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VBAPI函数:
mouse_event←模拟一次鼠标事件
--------------------------------------------------------------------------------------------------------------------------------------------------------
相关API声明:
mouse_event
↓
PrivateDeclareSubmouse_eventLib"user32"(ByValdwFlagsAsLong,ByValdxAsLong,ByValdyAsLong,ByValcButtonsAsLong,ByValdwExtraInfoAsLong)
--------------------------------------------------------------------------------------------------------------------------------------------------------
定义变量:
ConstMOUSEEVENTF_LEFTDOWN=&H2
ConstMOUSEEVENTF_LEFTUP=&H4
ConstMOUSEEVENTF_MIDDLEDOWN=&H20
ConstMOUSEEVENTF_MIDDLEUP=&H40
ConstMOUSEEVENTF_MOVE=&H1
ConstMOUSEEVENTF_ABSOLUTE=&H8000
ConstMOUSEEVENTF_RIGHTDOWN=&H8
ConstMOUSEEVENTF_RIGHTUP=&H10
--------------------------------------------------------------------------------------------------------------------------------------------------------
MOUSEEVENTF_LEFTDOWN'鼠标左键按下
MOUSEEVENTF_LEFTUP'鼠标松开
MOUSEEVENTF_RIGHTDOWN'鼠标右键按下
MOUSEEVENTF_RIGHTUP'鼠标右键松开
--------------------------------------------------------------------------------------------------------------------------------------------------------
代码:
PrivateDeclareSubmouse_eventLib"user32"(ByValdwFlagsAsLong,ByValdxAsLong,ByValdyAsLong,ByValcButtonsAsLong,ByValdwExtraInfoAsLong)
ConstMOUSEEVENTF_LEFTDOWN=&H2
ConstMOUSEEVENTF_LEFTUP=&H4
ConstMOUSEEVENTF_MIDDLEDOWN=&H20
ConstMOUSEEVENTF_MIDDLEUP=&H40
ConstMOUSEEVENTF_MOVE=&H1
ConstMOUSEEVENTF_ABSOLUTE=&H8000
ConstMOUSEEVENTF_RIGHTDOWN=&H8
ConstMOUSEEVENTF_RIGHTUP=&H10
'这里是鼠标左键按下和松开两个事件的组合即一次单击
mouse_eventMOUSEEVENTF_LEFTDOWNOrMOUSEEVENTF_LEFTUP,0,0,0,0
'模拟鼠标右键单击事件
mouse_eventMOUSEEVENTF_RIGHTDOWNOrMOUSEEVENTF_RIGHTUP,0,0,0,0
'两次连续的鼠标左键单击事件构成一次鼠标双击事件
mouse_eventMOUSEEVENTF_LEFTDOWNOrMOUSEEVENTF_LEFTUP,0,0,0,0
mouse_eventMOUSEEVENTF_LEFTDOWNOrMOUSEEVENTF_LEFTUP,0,0,0,0->