How to Create a Mouse Auto Clicker in Visual Basic

Introduction: Welcome to my tutorial on how to create an Auto Mouse Clicker in Visual Basic. Steps of Creation: Step 1: First lets create a form with; numericupdown1 to contain the amount of times to click, label1 to show the user the numericupdown1 will contain the amount of times to simulate clicks and a button to start the process. Step 2: Now lets make some variables to allow us to simulate clicks.
  1. Public Const MOUSEEVENTF_LEFTDOWN = &H2
  2. Public Const MOUSEEVENTF_LEFTUP = &H4
  3. Private Const MOUSEEVENTF_RIGHTDOWN = &H8
  4. Private Const MOUSEEVENTF_RIGHTUP = &H10
Step 3: Next we want to create a simple function which will handle the clicking.
  1. Declare Function apimouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
Step 4: Finally, we want to click the amount of times chosen in numericupdown1 when button1 is clicked.
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.     If (NumericUpDown1.Value > 0) Then
  3.         MsgBox("Please position your mouse over the clicking position, then press enter to close this messagebox and continue.")
  4.         For i As Integer = 0 To NumericUpDown1.Value - 1
  5.             Call apimouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  6.             Call apimouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
  7.         Next
  8.     End If
  9. End Sub
Project Complete! Below is the full source code and download to the project files.
  1. Public Class Form1
  2.     Public Const MOUSEEVENTF_LEFTDOWN = &H2
  3.     Public Const MOUSEEVENTF_LEFTUP = &H4
  4.     Private Const MOUSEEVENTF_RIGHTDOWN = &H8
  5.     Private Const MOUSEEVENTF_RIGHTUP = &H10
  6.  
  7.     Declare Function apimouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
  8.  
  9.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  10.         If (NumericUpDown1.Value > 0) Then
  11.             MsgBox("Please position your mouse over the clicking position, then press enter to close this messagebox and continue.")
  12.             For i As Integer = 0 To NumericUpDown1.Value - 1
  13.                 Call apimouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  14.                 Call apimouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
  15.             Next
  16.         End If
  17.     End Sub
  18. End Class

Add new comment