調(diào)用api
創(chuàng)新互聯(lián)建站長期為超過千家客戶提供的網(wǎng)站建設(shè)服務,團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為蒙自企業(yè)提供專業(yè)的成都做網(wǎng)站、網(wǎng)站設(shè)計,蒙自網(wǎng)站改版等技術(shù)服務。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
在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 '模擬鼠標左鍵按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模擬鼠標左鍵釋放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模擬鼠標中間鍵按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模擬鼠標中間鍵釋放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模擬鼠標右鍵按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模擬鼠標右鍵釋放
Public Const MOUSEEVENTF_MOVE = H1 '模擬鼠標指針移動
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模擬鼠標左鍵按下
您好,建議您使用mouse_event或者?Cursor.Position來實現(xiàn)。例如:
1. 您需要將鼠標移動dx, dy的位置。
Public?Sub?MouseMoveBy(ByVal?dx?As?Integer,?ByVal?dy?As?Integer)
Cursor.Position?=?New?Point(Cursor.Position.X?+?dx,?Cursor.Position.Y?+?dy)
End?Sub
或者
Public?Sub?MouseMoveBy(ByVal?dx?As?Integer,?ByVal?dy?As?Integer)
mouse_event(0,?dx,?dy,?0,?0)
End?Sub
2. 您需要將鼠標移動到x, y的位置
Public?Sub?MouseMoveTo(ByVal?x?As?Integer,?ByVal?y?As?Integer)
Cursor.Position?=?New?Point(x,?y)
End?Sub
請您試一下。
復雜的不會,來點兒簡單的,借用在listbox里按下鼠標時再移動,會高亮顯示選擇行,并且會隨鼠標移動而變化的這一特點改進的,不足之處是在listbox里,此時處于鼠標左鍵在按下狀態(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 '模擬鼠標左鍵按下
Private Sub ListBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseMove
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub
Imports?System.Runtime.InteropServices
DllImport("user32.dll")?
Private?Shared?Function?SetCursorPos(ByVal?X?As?Integer,?ByVal?Y?As?Integer)?As?Boolean????End?Function
DllImport("user32.dll")?
Private?Shared?Sub?mouse_event(ByVal?flags?As?MouseEventFlag,?ByVal?dx?As?Integer,?ByVal?dy?As?Integer,?ByVal?data?As?UInteger,?ByVal?extraInfo?As?UIntPtr)????End?Sub
Flags()
Private?Enum?MouseEventFlag?As?UInteger???
Move?=?H1?
LeftDown?=?H2
LeftUp?=?H4
RightDown?=?H8
RightUp?=?H10
MiddleDown?=?H20?
MiddleUp?=?H40?
XDown?=?H80?
XUp?=?H100
Wheel?=?H800?
VirtualDesk?=?H4000
Absolute?=?H8000?
End?Enum
SetCursorPos(intX,?intY)mouse_event(MouseEventFlag.LeftDown,?intX,?intY,?0,?UIntPtr.Zero)
mouse_event(MouseEventFlag.LeftUp,?intX,?intY,?0,?UIntPtr.Zero)