How can I get the x an y pos of the mouse?
Printable View
How can I get the x an y pos of the mouse?
Use the GetCursorPos and the WindowFromPoint Api functions to get the position of the mouse.
Code:Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Type POINTAPI
x As Long
y As Long
End Type
Dim P As POINTAPI
K$ = GetCursorPos(P)
J$ = WindowFromPoint(P.x, P.y)
Code:'this will show it anywhere on the form but not
'when it's over other controls
'find the mouse position anywhere on screen
'other than over the taskbar if visible
'text1 & text2 (2 textboxes)
'click anywhere on form to unload
Option Explicit
Private Sub Form_Activate()
Me.BorderStyle = 0 'none
Me.WindowState = 2 'max
End Sub
Private Sub Form_Click()
Unload Me
Set Form1 = Nothing
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = X
Text2.Text = Y
End Sub
Try this. Put the following into a Form with a Timer
Code:Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim prevX, prevY
Private Sub Timer1_Timer()
Dim PT As POINTAPI
GetCursorPos PT
If PT.x <> prevX Then Print PT.x
If PT.y <> prevY Then Print PT.y
prevX = PT.x: prevY = PT.y
End Sub