'Declare mouse events
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Declare PtrSafe Function GetKeyState Lib "user32.dll" (ByVal KeyCode As Long) As Integer
Const VK_LBUTTON = &H1
Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public cnt As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Sub test()
Dim lngCurPos As POINTAPI
cnt = 1
Do
GetCursorPos lngCurPos
DoEvents
If GetAsyncKeyState(1) Then
ThisWorkbook.Sheets(1).Cells(cnt, 1).Value = "X: " & lngCurPos.x & " Y: " & lngCurPos.y
cnt = cnt + 1
End If
Loop
End Sub