Reputation: 73
I'm trying to make my own auto-clicker (settable to left or right, depending on the radio button selection) and I can't seem to make the mouse click. In order to be able to set the delay wished for the auto-clicker, I've put it within the Timer1 (one for left click, one for right click). My questions are:
a) How can I make the mouse click when a certain key is pressed (e.g, F6).
b) How can I make it have the delay of Timer1/Timer2 for each click.
For the record, I wish for this auto-clicker to work EVERYWHERE, not just within the form.
Upvotes: 1
Views: 17694
Reputation: 31
I would imagine something like this would work, check vKey list to change hotkey.
Above Class:
Imports System.Threading
Main Class declares:
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()
Inside class:
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
Upvotes: 0
Reputation:
You can use 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
means left mouse button down.
&H4
means left mouse button up.
mouse_event(&H2, 0, 0, 0, 0)
mouse_event(&H4, 0, 0, 0, 0)
Upvotes: 2