[Solved] Continuously record mouse position in sheet

Keyboard macros or custom scripts

[Solved] Continuously record mouse position in sheet

Postby MrSpeed » 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:
Code: Select all   Expand viewCollapse view
GetCursorPos lngCurPos   REM gets the mouse from Windows
CellRange.value = lngCurPos.y    REM places the Y position in a cell.


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.

Code: Select all   Expand viewCollapse view
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

Many thanks in advance.
Last edited by MrSpeed on Sat Mar 16, 2019 2:56 pm, edited 1 time in total.
OpenOffice 4.1.6 on Windows 10
MrSpeed
 
Posts: 2
Joined: Sat Mar 16, 2019 3:18 am

Re: continuously record mouse position in sheet

Postby Zizi64 » Sat Mar 16, 2019 8:54 am

The programming interface of the Excel and the AOO/LO are very different.

The StarBasic programming language and the IDE of the AOO/LO is very simple to use. But you must often call a few ones of the thousands of the API functions. API: Application Programming Interface.
The functions of the MS VBA and the AOO/LO API are basicly different. You need rewrite all of the macros written in VBA.

You can use one of the excellent (third party) object inspection tools like the MRI or the XrayTool to examine the properties and methods of the programming objects.

And you can try the LibreOffice. The LO has a littlebit higher compatibility with the foreign file formats and the MS VBA macros.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8142
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: continuously record mouse position in sheet

Postby JeJe » Sat Mar 16, 2019 11:48 am

Openoffice provides you with listeners which means you can do these things directly without resorting to the Windows api.

There are mouse listeners which will give you information about the mouse location and also selection change listeners and many others. Access to these is a big advantage with OO.

Quickly finding a couple of threads which may be in the region of what you want to do:

viewtopic.php?f=45&t=60504

viewtopic.php?f=20&t=42487
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 551
Joined: Wed Mar 09, 2016 2:40 pm

Re: continuously record mouse position in sheet

Postby JeJe » Sat Mar 16, 2019 12:02 pm

Looking at your code - Change sleep 100 to Wait 100

(Edit:
in my first comment I was assuming you wanted to record the mouse position in the calc window for some purpose of working with calc. If you want to record the mouse position generally then you can't do that with an OO listener, and need your method)
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 551
Joined: Wed Mar 09, 2016 2:40 pm

Re: Continuously record mouse position in sheet

Postby MrSpeed » Sat Mar 16, 2019 2:55 pm

:D Sleep to Wait did the trick! Thanks JeJe!! So I guess the program halted on sleep then? I don't fully understand but it works. And Thanks Zizi64 for the tips. Good to know.
OpenOffice 4.1.6 on Windows 10
MrSpeed
 
Posts: 2
Joined: Sat Mar 16, 2019 3:18 am

Re: [Solved] Continuously record mouse position in sheet

Postby JeJe » Sat Mar 16, 2019 3:27 pm

Yeah, I don't know why sleep doesn't work here either, but its generally better to use an inbuilt function anyway.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 551
Joined: Wed Mar 09, 2016 2:40 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 4 guests