I've got my code all ready to go, except what i want to do is have the 'btnSTART' button move the mouse to the selected coordinates, and Left Click down then Left Click up. Here's my code:

Public Class Form1

    Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Integer
    Dim mousepos As Point
    ' This stores the cordinates of the mouse cursors location
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Start()
    End Sub
    Public Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim R As Long = GetCursorPos(mousepos) ' You'll get your location in mousepos
        lblCoordinates.Text = "Current Mouse Location: " & vbCrLf & "X: " & mousepos.X & vbCrLf & "Y: " & mousepos.Y
    End Sub

    Private Sub btnSetCoordinate_Click(sender As Object, e As EventArgs) Handles btnSetCoordinate.Click
        txtCoordinateX.Text = mousepos.X
        txtCoordinateY.Text = mousepos.Y
    End Sub

    Private Sub btnSTART_Click(sender As Object, e As EventArgs) Handles btnSTART.Click
    End Sub
End Class

All help is much appreciated!

Recommended Answers

All 3 Replies

When you found GetCursorPos in ther User32.dll, did a little bell not tinkle to the sound of maybe SetCursorPos? =0)

I'm a cheeky chap

Public Declare Auto Function SetCursorPos Lib "User32.dll" 
    (X As Integer, Y As Integer) As Boolean

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

    SetCursorPos(50, 50)

End Sub

There you go, so close my friend.

If the thing you want to click is a button you can always execute it by

myButton.PerformClick()

doh...

[Whispers] I hope he's making a demo which physically moves the mouse pointer then clicks the button, which doesn't render my answering only the first half of the question entirely pointless [/Whispers]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.