1个回答
2014-03-07
展开全部
Option Explicit
Private 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 _
)
'Option_Tag标示选择了哪一种模拟事件
Dim Option_Tag As Integer
'OnTest标示是否处于模拟状态,以便我们停止模拟
Dim OnTest As Boolean
'对API变量的定义
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
'控制 模拟的开始与结束
Private Sub Command1_Click()
'如果不处于模拟状态
If OnTest = False Then
Command1.Caption = "快停下来吧"
Timer1.Enabled = True
OnTest = True
'如果处于模拟状态
Else
Command1.Caption = "试一试"
Timer1.Enabled = False
OnTest = False
End If
End Sub
'窗体加载时一些变量需要设置
Private Sub Form_Load()
Option_Tag = 1
Timer1.Enabled = False
OnTest = False
End Sub
'选择了模拟“鼠标左键单击事件”
Private Sub Option1_Click()
Option_Tag = 1 '左键单击事件
Option2.Value = False
Option3.Value = False
End Sub
'选择了模拟“鼠标右键单击事件”
Private Sub Option2_Click()
Option_Tag = 2 '右键单击事件
Option1.Value = False
Option3.Value = False
End Sub
'选择了模拟“鼠标双击事件”
Private Sub Option3_Click()
Option_Tag = 3 '双击事件
Option1.Value = False
Option2.Value = False
End Sub
'每隔一秒中模拟一次鼠标事件
Private Sub Timer1_Timer()
If Option_Tag = 1 Then
'调用了mouse_event函数,其参数的设置见前面说明
'如果同时要模拟两个鼠标事件,可以用 Or 将两个参数连接
'这里是 鼠标左键按下 和松开两个事件的组合即一次单击
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
ElseIf Option_Tag = 2 Then
'模拟鼠标右键单击事件
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
Else
'两次连续的鼠标左键单击事件 构成一次鼠标双击事件
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End If
End Sub
Private 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 _
)
'Option_Tag标示选择了哪一种模拟事件
Dim Option_Tag As Integer
'OnTest标示是否处于模拟状态,以便我们停止模拟
Dim OnTest As Boolean
'对API变量的定义
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
'控制 模拟的开始与结束
Private Sub Command1_Click()
'如果不处于模拟状态
If OnTest = False Then
Command1.Caption = "快停下来吧"
Timer1.Enabled = True
OnTest = True
'如果处于模拟状态
Else
Command1.Caption = "试一试"
Timer1.Enabled = False
OnTest = False
End If
End Sub
'窗体加载时一些变量需要设置
Private Sub Form_Load()
Option_Tag = 1
Timer1.Enabled = False
OnTest = False
End Sub
'选择了模拟“鼠标左键单击事件”
Private Sub Option1_Click()
Option_Tag = 1 '左键单击事件
Option2.Value = False
Option3.Value = False
End Sub
'选择了模拟“鼠标右键单击事件”
Private Sub Option2_Click()
Option_Tag = 2 '右键单击事件
Option1.Value = False
Option3.Value = False
End Sub
'选择了模拟“鼠标双击事件”
Private Sub Option3_Click()
Option_Tag = 3 '双击事件
Option1.Value = False
Option2.Value = False
End Sub
'每隔一秒中模拟一次鼠标事件
Private Sub Timer1_Timer()
If Option_Tag = 1 Then
'调用了mouse_event函数,其参数的设置见前面说明
'如果同时要模拟两个鼠标事件,可以用 Or 将两个参数连接
'这里是 鼠标左键按下 和松开两个事件的组合即一次单击
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
ElseIf Option_Tag = 2 Then
'模拟鼠标右键单击事件
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
Else
'两次连续的鼠标左键单击事件 构成一次鼠标双击事件
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询