set mouse position and click

  • 14 years ago

    Hi!

    I want to set the mouse position programmatically and do a click.

    I used the code bellow, but don't work.

    Private Declare Function SetCursorPos Lib "user32.dll" (byval x as Long, byval y as Long) as Long

    SetCursorPos(50,50)

    I got an error: "A call to PInvoke function 'SetCursorPos' has unbalanced the stack" 

    How can I set the mouse position properly and do a click.

    Thanks!

    Tamas

  • 14 years ago

    Given two buttons on a form, this code will move the mouse into the top right of the second button:

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

      Dim pt As Point

      pt.X = Button2.Right - 10

      pt.Y = Button2.Top + 10

      pt = PointToScreen(pt)

      Cursor.Position = pt

    End Sub

    Will endeavour to look at simulating a generic mouse click - I've only ever needed to simulate mouse clicks on known objects, via control.PerformClick.  I'll post back here if I find anything.

    HTH

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra