左/右鼠标单击功能VB.NET

时间:2014-05-22 10:15:43

标签: vb.net automation click

我试图制作自己的自动点击器(可设置为向左或向右,具体取决于单选按钮的选择),我似乎无法点击鼠标。为了能够设置自动点击器的延迟,我将它放在Timer1中(一个用于左键单击,一个用于右键单击)。我的问题是:

a)如何在按下某个键时单击鼠标(例如,F6)。

b)如何使每次点击都有Timer1 / Timer2的延迟。

为了记录,我希望这个自动点击器能够在任何地方工作,而不仅仅是在表单中。

2 个答案:

答案 0 :(得分:2)

您可以使用user32.dll lib。

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

&H2表示鼠标左键&H4表示鼠标左键

mouse_event(&H2, 0, 0, 0, 0)
mouse_event(&H4, 0, 0, 0, 0)

答案 1 :(得分:0)

我会想象这样的东西会起作用,请检查vKey列表以更改热键。

以上课程:

Imports System.Threading

主类声明:

Dim ClickTimer As System.Threading.Thread = New System.Threading.Thread(AddressOf DoClicks)
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Integer
Dim exit_thread As Boolean = False
Dim ClickerHotkey As Integer = &H20 '0x20 = space

的Form_Load:

ClickTimer.Start()

内部课程:

Public Function DoClicks()
        While (Not exit_thread)
            If GetAsyncKeyState(ClickerHotkey) Then
                mouse_event(&H2, 0, 0, 0, 1)
                mouse_event(&H4, 0, 0, 0, 1)
            End If
            Thread.Sleep(15)
        End While
End Function

Form_OnClose:

exit_thread = true
相关问题