大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
用API函数mouse_event可以做到
济源网站建设公司成都创新互联公司,济源网站设计制作,有大型网站制作公司丰富经验。已为济源上千提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的济源做网站的公司定做!
函数及常数声明:
Public 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_ABSOLUTE = H8000 ' absolute move
Public Const MOUSEEVENTF_LEFTDOWN = H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = H40 ' middle button up
Public Const MOUSEEVENTF_MOVE = H1 ' mouse move
Public Const MOUSEEVENTF_RIGHTDOWN = H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = H10 ' right button up
Public Const MOUSEEVENTF_WHEEL = H800
测试代码:建立一个窗体,加一个按钮和一个timer
Option Explicit
Private Sub Command1_Click()
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
For i = 0 To 100
DoEvents
mouse_event MOUSEEVENTF_WHEEL, 0, 0, 10, 0
Next
For i = 0 To 100
DoEvents
mouse_event MOUSEEVENTF_WHEEL, 0, 0, -10, 0
Next
End Sub
调用api
在Visual Baisc点虐 中的声明:
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)模拟鼠标左键按下
1. Case 3 改成 Case 4
另外,在你不知道原因的情况下你可以在这个过程中加入debug.print button
这样 你在窗体上任意按下鼠标的键,你就能从“立即”窗口中知道这个键的botton值是多少。这个办法是经常有用的办法!我觉得你应该学会用这类办法去解决一些比较普通的问题。
如这里你可以这样写:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
debug.print "Botton=";botton,"Shift=";shift,"X=";x,"Y=";y
End Sub
这样你单击鼠标 你就知道了各个值 (逆向思维),然后编程的时候就写这个值 ……
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 的详解,大致使用如上