Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting MouseMove anywhere on screen

Status
Not open for further replies.

5ilver5aracen

Programmer
Oct 24, 2004
32
0
0
GB
Hi
Does anyone know how I can read the mouse x and y even when the mouse is outside of my form?
Many thanks in advance
 
this is how I'm doing it in MS Access should be about the same in VB. the Form Timer will be a little different.

Code:
Private Type PointAPI
    X As Long
    Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long



Private Sub Mouse_Position(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim Pnt As PointAPI   ' Declare a variable to use the UDT
    GetCursorPos Pnt      ' Call the API to return the x and y coordinates of the mouse pointer
    'Me.Cls
    'Me.Print "MousePointer is located at "; Pnt.X; ","; Pnt.Y
    Me.txtX = Pnt.X
    Me.txtY = Pnt.Y
    
End Sub



Private Sub Form_Timer()
    Call Mouse_Position(1, 0, 0, 0)
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top