前邊談了模擬鍵盤,下面說說模擬鼠標。
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要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->