我终于找到办法了获取鼠标单击的精确坐标(相对于文档)。
我设法从底部的状态栏获取信息,它通常显示坐标(对我来说以厘米为单位)。
这是我现在用来获取位置 (X / Y) 的函数:
REM // Warning: If there is currently a selection, the returning Point will instead show the coordinates of the selection!
Sub GetMousePositionOnDocument as com.sun.star.awt.Point
Dim aPosition As New com.sun.star.awt.Point
Dim o1, o2, o3, o4, o5, o6
REM // First get AccessibleContext of the Window of the active Frame of the Application
o1 = StarDesktop.ActiveFrame.ContainerWindow.AccessibleContext
REM // 7th AC of o1 is the StatusBar at the bottom;
o2 = o1.GetAccessibleChild(6).AccessibleContext
REM // 2nd AC of o2 is the Position + Size of the Selection (e.g: "10,95 / 14,980,00 x 0,00")
o3 = o2.GetAccessibleChild(1)
o4 = o3.GetText()
REM // Taking out only the coordinates from o4
REM // TODO: Check for negatives (longer)
o5 = LEFT(o4, 4)
o6 = MID(o4, 8, 5)
aPosition.X = o5
aPosition.Y = o6
REM // Return
GetMousePositionOnDocument = aPosition
End Sub
注意:这个函数是在我之前的内部调用的Listener_mousePressed
从上面。
希望这对其他人也有效。
我是怎么找到的?
我花了很多时间在调试器中手动检查该组件和 Stars Desktop 的每个 Windows ApplicationContext。
如果需要其他值,这是迭代 ThisDesktop 的起点。ThisComponent.CurrentController.Frame.ComponentWindow.AccessibleContext
未来的改进
我“知道” GetAccessibleChild()-Function 的索引,因为我检查了调试器。当然有更好的方法可以到达o3
并且您不应该期望每个人都具有相同的 AccessibleContext。