如何在 Mac 触控板上获取指点设备的坐标?

发布于 2024-09-24 21:42:05 字数 392 浏览 2 评论 0原文

当用户在触控板上做出手势时,我想获取手指的位置。

我已经迷上了滑动时触发的 swipeWithEvent 。在该 NSEvent 中,有一个方法 deltaX 报告运动的变化。还有absoluteX方法看起来很有希望,但除了以下断言失败之外,我无法返回任何内容:

发送到事件“NSEvent: type=Swipe loc=(394,335) time=3893.8 flags=0x100 win=0x10022fdc0 winNum的消息无效” =586 ctxt=0x0 deltaX=-1.000000 deltaY=0.000000"

错误消息中的“loc”值随着时间的推移略有变化,但据我了解,这不是正确的值,因为变化太小。

那么,如何在触控板上正确使用 NSEvent 的absoluteX?

I'd like to get the finger's position when user makes a gesture on the trackpad.

I've already hooked on to swipeWithEvent that triggers on swipe. Within that NSEvent there's a method deltaX that reports the change of the movement. There's also absoluteX method that looks promising, but I can't get it to return anything but the following assertion failure:

Invalid message sent to event "NSEvent: type=Swipe loc=(394,335) time=3893.8 flags=0x100 win=0x10022fdc0 winNum=586 ctxt=0x0 deltaX=-1.000000 deltaY=0.000000"

The 'loc' value the in the error message changes a bit over time, but to my understanding it's not the right value because the change is too small.

So, how can I properly use NSEvent's absoluteX on a trackpad?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫人生路 2024-10-01 21:42:05

来自 -[NSEvent AbsoluteX] 的文档:

要使坐标有效,
接收者应该代表一个事件
由平板电脑指点设备生成
(否则返回 0)。这个方法
仅对带有 a 的鼠标事件有效
NSTabletPointEventSubtype 的子类型
对于 NSTabletPoint 类型的事件

我认为如果您需要在非平板电脑设备上获取相同的信息,您需要告诉 Apple(通过错误报告器或 DTS)您的要求,因为 API 目前不支持它。

From the documentation for -[NSEvent absoluteX]:

For the coordinate to be valid, the
receiver should represent an event
generated by a tablet pointing device
(otherwise 0 is returned). This method
is valid only for mouse events with a
subtype of NSTabletPointEventSubtype
and for events of type NSTabletPoint

I would think if you need to get the same information on a non-tablet device, you need to tell Apple (via the bug reporter or DTS) about your requirement as the API doesn't currently support it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文