VB6自动点击程序启动但不停止

时间:2013-08-14 05:53:47

标签: vb6 mouseevent

我正在VB6中编写一个自动点击程序。我的想法是,如果我在同时按住右键同时按住左键单击,它会自动开始单击,直到您放开任何一个。

Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Dim lefter As Boolean, righter As Boolean
Public Sub LeftClick()
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Private Sub Form_Load()
    lefter = False
    righter = False
    Timer1.Interval = 80
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(2) = 0 Then
    righter = False
Else: righter = True
End If
If GetAsyncKeyState(1) = 0 Then
    lefter = False
Else: lefter = True
End If
If lefter = True Then
    If righter = True Then
        LeftClick
    End If
End If
End Sub

Timer1每隔80毫秒触发一次。

在我尝试通过释放左键单击(同时继续保持右键单击)来停止它之前,该功能很有效,程序在启动后似乎完全忽略了。

相对来说,这不是一个问题而且很容易解决,但我宁愿修复它,以便我根本不需要解决它。

提前谢谢。

3 个答案:

答案 0 :(得分:1)

GetAsyncKeyState indicates的返回值,无论该密钥当前是还是,是否自上次调用后是否按下了该键。如果您只是需要知道密钥当前是否已关闭,请尝试以下操作:

Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Timer1_Timer()
Dim righter As Boolean, lefter As Boolean
If GetAsyncKeyState(2) = 0 Then
    righter = False
Else: righter = True
End If
If GetAsyncKeyState(1) = 0 Then
    lefter = False
Else: lefter = True
End If
If lefter = True Then
    If righter = True Then
        LeftClick
    End If
End If
End Sub
Sub LeftClick()
  Debug.Print Timer & " LeftClick"
End Sub

答案 1 :(得分:1)

如果你添加:

Debug.Print Rnd

对于你的Public Sub LeftClick(),你会注意到它应该被触发了。您将不得不寻求另一种发送鼠标事件的方法。

答案 2 :(得分:0)

这样的事情应该做:

If GetAsyncKeyState(1) And GetAsyncKeyState(2) Then LeftClick