Ho bisogno di simulare dei click in determinate posizioni ogni tot secondi, essendo questi click ripetitivi avevo pensato quindi ad un ciclo. Inoltre pensavo per dargli una pausa temporale tra un click e l'altro di utilizzare i thread in questo modo:

codice:
Public Class x3
    'variabile per il ciclo di funzionamento
    Dim a As Integer
    'Funzione per simulare il click del mouse in determinate coordinate
    Enum meFlags As Integer
        MOUSEEVENTF_MOVE = &H1
        MOUSEEVENTF_LEFTDOWN = &H2
        MOUSEEVENTF_LEFTUP = &H4
        MOUSEEVENTF_RIGHTDOWN = &H8
        MOUSEEVENTF_RIGHTUP = &H10
        MOUSEEVENTF_MIDDLEDOWN = &H20
        MOUSEEVENTF_MIDDLEUP = &H40
        MOUSEEVENTF_XDOWN = &H80
        MOUSEEVENTF_XUP = &H100
        MOUSEEVENTF_WHEEL = &H800
        MOUSEEVENTF_VIRTUALDESK = &H4000
        MOUSEEVENTF_ABSOLUTE = &H8000
    End Enum
    Declare Sub mouse_event Lib "user32" (ByVal dwFlags As meFlags, ByVal Coords As Drawing.Point, ByVal dwData As Integer, ByVal dwExtraInfo As UIntPtr)
    Sub SimulateClick(ByVal Location As Drawing.Point)
        Dim trect As Drawing.Rectangle = Screen.GetBounds(Location)
        Dim tpnt As New Drawing.Point(65535.0 / trect.Width * Location.X, 65535.0 / trect.Height * Location.Y)
        mouse_event(meFlags.MOUSEEVENTF_MOVE Or meFlags.MOUSEEVENTF_ABSOLUTE, tpnt, 0, New UIntPtr(Convert.ToUInt32(0)))
        mouse_event(meFlags.MOUSEEVENTF_LEFTDOWN Or meFlags.MOUSEEVENTF_ABSOLUTE, tpnt, 0, New UIntPtr(Convert.ToUInt32(0)))
        mouse_event(meFlags.MOUSEEVENTF_LEFTUP Or meFlags.MOUSEEVENTF_ABSOLUTE, tpnt, 0, New UIntPtr(Convert.ToUInt32(0)))
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        Dim pnt As New Point(x1.Text, y1.Text)
        Dim pnt2 As New Point(x1.Text + 50, y1.Text + 20)
        a = 2
        While (a > 1)
            Threading.Thread.Sleep(5000)
            SimulateClick(pnt)
            Threading.Thread.Sleep(5000)
            SimulateClick(pnt2)
            Threading.Thread.Sleep(5000)
        End While

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        a = 1
    End Sub
End Class
Praticamente il tutto cicla (alla pressione del button1) finchè a > 1 e con il button2_click simulo un tasto termina per stoppare il ciclo. Il problema è che con i thread.sleep "mi mette tutto in sleep" e quindi non è visualizzato il tasto per terminare tutto.

Come posso fare a risolvere questo problema? posso utilizzare qualche altra funzione per simulare il tempo di attesa? per altro esiste un modo di conversione preciso del tempo dello sleep? cioè quei 5000 non mi sembrano 5 secondi!

Sarebbe anche più ottimale se potessi simulare qualcosa del tipo "alle 8:30" esegui questo click.

Vi ringrazio in anticipo per la vostra disponibilità,
Neptune.