So I am coding a mouse clicker and got everything working like grabbing the position, setting how many times you want to repeat, etc. The only problem is getting the mouse to click on every loop through my if loop on the timer. The goal is basically to make the mouse click on that position every time the timer ticks from the set interval. Any help you could provide would be excellent!
Code:
Public Class Form1
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)
Private Declare Function SetCursorPos Lib "user32" (ByVal XCoord As Integer, ByVal YCoord As Integer) As Integer
Public coords As List(Of Point)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Private Sub CoordinatesButton_Click(sender As Object, e As EventArgs) Handles CoordinatesButton.Click
TextBox1.Text = (MousePosition.X)
TextBox2.Text = (MousePosition.Y)
coords.Add(MousePosition)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
coords = New List(Of Point)
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
Timer1.Start()
End Sub
Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
Timer1.Stop()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
coords.Clear()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If repeat > 0 Then
Dim p As Point = coords(0)
SetCursorPos(p.X, p.Y)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
repeat = repeat - 1
TextBox3.Text = repeat
Else
Timer1.Stop()
TextBox3.Text = saveRepeat
repeat = saveRepeat
End If
End Sub
Private Sub RepeatToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RepeatToolStripMenuItem.Click
Form2.Show()
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub ClickerHelpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClickerHelpToolStripMenuItem.Click
Help.Show()
End Sub
End Class