调用api
创新互联建站长期为超过千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为蒙自企业提供专业的成都做网站、网站设计,蒙自网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。
在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来实现。例如:
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里,此时处于鼠标左键在按下状态。
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)
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款