Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
創(chuàng)新互聯(lián)專(zhuān)注網(wǎng)站設(shè)計(jì),以設(shè)計(jì)驅(qū)動(dòng)企業(yè)價(jià)值的持續(xù)增長(zhǎng),網(wǎng)站,看似簡(jiǎn)單卻每一個(gè)企業(yè)都需要——設(shè)計(jì),看似簡(jiǎn)潔卻是每一位設(shè)計(jì)師的心血 十載來(lái),我們只專(zhuān)注做網(wǎng)站。認(rèn)真對(duì)待每一個(gè)客戶(hù),我們不用口頭的語(yǔ)言來(lái)吹擂我們的優(yōu)秀,近1000家的成功案例見(jiàn)證著我們的成長(zhǎng)。
Dim postion1 As New Point
mouse_event(H1 Or H8000, postion1.X * 65535 / 1366, postion1.Y * 65535 / 768, 0, 0)
'按絕對(duì)位置移動(dòng)鼠標(biāo)
'在鼠標(biāo)坐標(biāo)系統(tǒng)中,屏幕在水平和垂直方向上均勻分割成65535×65535個(gè)單元,
'當(dāng)前所用顯示屏分辨率為1366*768
'所以要進(jìn)行如上轉(zhuǎn)換
mouse_event(H2, 0, 0, 0, 0) '鼠標(biāo)左鍵按下
mouse_event(H4, 0, 0, 0, 0) '鼠標(biāo)左鍵彈起
msdn上有 mouse_event 的詳解,大致使用如上
調(diào)用api
在Visual Baisc.net中的聲明:
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = H2 '模擬鼠標(biāo)左鍵按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模擬鼠標(biāo)左鍵釋放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模擬鼠標(biāo)中間鍵按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模擬鼠標(biāo)中間鍵釋放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模擬鼠標(biāo)右鍵按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模擬鼠標(biāo)右鍵釋放
Public Const MOUSEEVENTF_MOVE = H1 '模擬鼠標(biāo)指針移動(dòng)
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模擬鼠標(biāo)左鍵按下
復(fù)雜的不會(huì),來(lái)點(diǎn)兒簡(jiǎn)單的,借用在listbox里按下鼠標(biāo)時(shí)再移動(dòng),會(huì)高亮顯示選擇行,并且會(huì)隨鼠標(biāo)移動(dòng)而變化的這一特點(diǎn)改進(jìn)的,不足之處是在listbox里,此時(shí)處于鼠標(biāo)左鍵在按下?tīng)顟B(tài)。
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = H2 '模擬鼠標(biāo)左鍵按下
Private Sub ListBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseMove
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub