Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Jun 24, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

MoveMouseCursor - Move the mouse to given coordinates

Private Type POINTAPI
    X As Long
    Y As Long
End Type

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, _
    lpPoint As POINTAPI) As Long

' Mouse the mouse cursor.
' If a window handle is passed, the coordinates
' are considered to be relative to that window's client area,
' otherwise they are considered to be relative to the screen.
' In all cases, coordinates are in pixels

Sub MoveMouseCursor(ByVal X As Long, ByVal Y As Long, _
    Optional ByVal hWnd As Long)
    If hWnd = 0 Then
        SetCursorPos X, Y
        Dim lpPoint As POINTAPI
        lpPoint.X = X
        lpPoint.Y = Y
        ClientToScreen hWnd, lpPoint
        SetCursorPos lpPoint.X, lpPoint.Y
    End If
End Sub
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date