It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

SetCursorPos Problem

Moderator: dafunkymunky

SetCursorPos Problem

Postby Krytikal on Fri May 14, 2010 8:03 am

Hey all,

When I use the code below (got from a tutorial) it only sets the cursors X pos and not the Y pos. I've tried so many things to get this working and now I need some guidance. Thanks.

Code: Select all
Public Class Form1
    Private Structure POINTAPI
        Dim X As Long
        Dim Y As Long
    End Structure

    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, _
        ByVal Y As Long) As Long
    Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, _
    ByVal lpPoint As POINTAPI) As Long

    Public Sub MoveMouseCursor(ByVal X As Long, ByVal Y As Long, _
    Optional ByVal hWnd As Long = 0)
        If hWnd = 0 Then
            SetCursorPos(X, Y)
        Else
            Dim lpPoint As POINTAPI
            lpPoint.X = X
            lpPoint.Y = Y
            ClientToScreen(hWnd, lpPoint)
            SetCursorPos(lpPoint.X, lpPoint.Y)
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        MoveMouseCursor(500, 500)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class
Krytikal
 
Posts: 1
Joined: Fri May 14, 2010 8:02 am

Re: SetCursorPos Problem

Postby bytelogik on Sat May 15, 2010 9:42 am

Hi,

I checked your code in VB6 (i don't have .Net) , it is correct.
Try using a single line direct SetCursorPos code from a command button, e.g.,

SetCursorPos 400,130

and check out if the API works properly.

Good Luck.
bytelogik
 
Posts: 12
Joined: Tue Oct 06, 2009 7:24 pm


Who is online

Users browsing this forum: No registered users and 3 guests