[Solved] Continuously record mouse position in sheet
Posted: Sat Mar 16, 2019 4:38 am
Hi all, I am trying to convert a macro from Excel VBA to Calc Basic. This is my first venture into Calc Basic.
The macro records the Y mouse position in a cell then moves down one cell and records the next mouse position. There is a 100 milli second delay between recordings. It works but only when mouse movements are not continuous.
The full code further below is mostly declarations. The actual recording of the mouse is done by:
I have the problem in Calc Basic only, not in the original VBA. In Calc Basic as long as the mouse is moving, the GetCursorPos is halting the macro. Only when the mouse stops for a brief moment the position is passed on and the macro continues. However I want to capture the mouse position while the mouse is continuously moving. Anybody any idea? The mouse will be moving all the time.
Many thanks in advance.
The macro records the Y mouse position in a cell then moves down one cell and records the next mouse position. There is a 100 milli second delay between recordings. It works but only when mouse movements are not continuous.
The full code further below is mostly declarations. The actual recording of the mouse is done by:
Code: Select all
GetCursorPos lngCurPos REM gets the mouse from Windows
CellRange.value = lngCurPos.y REM places the Y position in a cell.
Code: Select all
REM ***** BASIC *****
Option Explicit
Declare Sub Sleep Lib "C:\WINDOWS\system32\kernel32.dll" Alias "Sleep" ( ByVal dwMilliseconds As Long)
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Sub LogYMousePosition()
Dim lngCurPos As POINTAPI
Dim Doc As Object
Dim Sheet As Object
Dim CellRange As Object
Dim i as Long
i=1
Doc = ThisComponent
Sheet = Doc.Sheets.getByName("Sheet1")
CellRange = Sheet.getCellByPosition(0,i)
Do
GetCursorPos lngCurPos
CellRange.value = lngCurPos.y
i=i+1
CellRange = Sheet.getCellByPosition(1,i)
Sleep 100
if i=70 then i=0 rem for testing only
Loop
End Sub