首先需要一个判断鼠标位置的api,然后单位时间进行判断,如果某时间鼠标的位置超出了窗体,则用另一个api来设置鼠标位置
创新互联公司科技有限公司专业互联网基础服务商,为您提供成都西云数据中心,高防物理服务器租用,成都IDC机房托管,成都主机托管等互联网服务。
这个都不难理解?详情可查看vbgood的api手册
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)
Dim postion1 As New Point
mouse_event(H1 Or H8000, postion1.X * 65535 / 1366, postion1.Y * 65535 / 768, 0, 0)
'按绝对位置移动鼠标
'在鼠标坐标系统中,屏幕在水平和垂直方向上均匀分割成65535×65535个单元,
'当前所用显示屏分辨率为1366*768
'所以要进行如上转换
mouse_event(H2, 0, 0, 0, 0) '鼠标左键按下
mouse_event(H4, 0, 0, 0, 0) '鼠标左键弹起
msdn上有 mouse_event 的详解,大致使用如上
调用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 '模拟鼠标左键按下
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)模拟鼠标左键按下