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