vb 從零開始(五)
前邊談了模擬鍵盤,下面說說模擬滑鼠。
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要vbapi函數:
mouse_event←模擬一次滑鼠事件
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關api聲明:
mouse_event
privatedeclaresubmouse_eventlib"user32"(byvaldwflagslong,byvalaslong,byvalaslong,byvalcbuttonslong,byvaldwextrainfolong)
--------------------------------------------------------------------------------------------------------------------------------------------------------
定義變數:
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"(byvaldwflagslong,byvalaslong,byvalaslong,byvalcbuttonslong,byvaldwextrainfolong)
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_leftdownmouseeventf_leftup,0,0,0,0
'模擬滑鼠右鍵單擊事件
mouse_eventmouseeventf_rightdownmouseeventf_rightup,0,0,0,0
'兩次連續的滑鼠左鍵單擊事件構成一次滑鼠雙擊事件
mouse_eventmouseeventf_leftdownmouseeventf_leftup,0,0,0,0
mouse_eventmouseeventf_leftdownmouseeventf_leftup,0,0,0,0