Credits: Erra
Language: VB6
The reason I made this for myself is that I play the game Conquer Online and in that game you have to pretty much right-click 24/7.
So first put two timers on the form and name them respectively tmrCDown and tmrRC (timer C Key Down & timer Right Click) and also two labels, one being called Label1 and one being called lblStatus.
tmrCDown's interval should be set to 100 (100 milliseconds) and tmrRC's interval should be set to 1500 (1500 milliseconds, or how fast you want the auto-clicker to auto-click).
Then you'd be best off adding a module to the project (Right-click Form1->Add->Module) and then add this code at the beginning:
Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
That will declare the sub "mouse_event" and the function "GetAsyncKeyState", which are used respectively to click a mouse button (send a mouse event) and check for pressed keys.
Let's continue, we will be needing two constants (not really needing, but it'll keep it all simple):
Code:
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Those two constants are there to help you remember what the values are for, as we will use them in the following sub:
Code:
Public Sub Mouse_RightClick()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub
First declaring the sub Mouse_RightClick and then when called it will send the same mouse event that you send when you push the right mouse button down and then the one you send when you release the right mouse button.
To simplify things even more, we will make a function for checking if the key is being pressed (that is, with GetAsyncKeyState to pause the auto-clicker):
Code:
Public Function CKeyDown() As Boolean
If (GetAsyncKeyState(vbKeyC)) Then
CKeyDown = True
Else
CKeyDown = False
End If
End Function
First declaring the function CKeyDown as Boolean (meaning it'll return either true or false) which then checks if the C button is being pressed (vbKeyC) and if it is, return True, if not, return False.
Now to the easy part; Double click tmrCDown and insert this code:
Code:
If CKeyDown = True Then
tmrRC.Enabled = Not (tmrRC.Enabled)
If tmrRC.Enabled = True Then
lblStatus.Caption = "Status: Enabled."
Label1.Caption = "Disable by pressing C"
ElseIf tmrRC.Enabled = False Then
lblStatus.Caption = "Status: Disabled."
Label1.Caption = "Enable by pressing C"
End If
End If
First it will call the function CKeyDown and if it returns True then it will either enable or disable tmrRC (you'll see what it does in a minute), then it checks if tmrRC was enabled or disabled, if it was enabled then it will say so or if it was disabled it'll say so.
Now the only remaining code is tmrRC's code, double click tmrRC and insert this code:
It will now start right clicking as fast as you set the timer to.
Form1's code should now look pretty much like this:
Code:
Private Sub tmrCDown_Timer()
If CKeyDown = True Then
tmrRC.Enabled = Not (tmrRC.Enabled)
If tmrRC.Enabled = True Then
lblStatus.Caption = "Status: Enabled."
Label1.Caption = "Disable by pressing C"
ElseIf tmrRC.Enabled = False Then
lblStatus.Caption = "Status: Disabled."
Label1.Caption = "Enable by pressing C"
End If
End If
End Sub
Private Sub tmrRC_Timer()
Mouse_RightClick
End Sub
and the module you created (module1 if you haven't changed the name):
Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Declare Sub mouse_event Lib "user32.dll" (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_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Sub Mouse_RightClick()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub
Public Function CKeyDown() As Boolean
If (GetAsyncKeyState(vbKeyC) And &H8000) Then
CKeyDown = True
Else
CKeyDown = False
End If
End Function
I hope this "tutorial" was useful for you :angel:
Regards,
Erra
Ps. If you want it to left click then add this after the other constants:
Code:
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
and add the sub Mouse_LeftClick(), into the module you created earlier:
Code:
Public Sub Mouse_LeftClick()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
I'll post a guide on how to make you able to set where to push the mousebutton as soon as I get the time to.