如何存储(和使用)当前鼠标位置?

发布于 2024-08-19 08:06:34 字数 658 浏览 6 评论 0原文

存储当前鼠标位置(系统范围)然后(稍后)将鼠标放在该存储点的最佳方法是什么?

[NSEvent mouseLocation] 获取我的位置,我可以使用 CGEventMouseMoved ,但它们各自使用不同的坐标系统(我相信 y=0 是 NSEvent 的顶部和 CGEvent 的底部)。

我担心捕获屏幕高度并使用它在两者之间进行转换的稳健性 - 或者这是最好的方法?

What is the best way to store the current mouse position (system-wide) and then (later) put the mouse at that stored point?

[NSEvent mouseLocation] gets me the position, and I can move the mouse with a CGEventMouseMoved, but they each use a different co-ordinates system (I believe y=0 is the top for NSEvent and the bottom for a CGEvent).

I'm worried about the robustness of capturing the screen height and using it to convert between the two - or is this the best approach?

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

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

发布评论

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

评论(2

番薯 2024-08-26 08:06:34

您可以使用 CGEventTap 来获取鼠标事件NSEvent 的。然后,您可以在活动到来时选择翻转或不翻转。

(我相信 y=0 是 NSEvent 的顶部和 CGEvent 的底部)。

你的做法是错误的。 Quartz采用翻转,即y=0=top。 AppKit使用unflipped,即y=0=bottom。 (编辑:对于事件,即 Quartz 2D,绘图 API,使用未翻转的坐标,与 AppKit 相同。)

You could use a CGEventTap to get the mouse events instead of NSEvent. Then you have your choice of flipped or unflipped at the time the event arrives.

(I believe y=0 is the top for NSEvent and the bottom for a CGEvent).

You have that the wrong way around. Quartz uses flipped, which is y=0=top. AppKit uses unflipped, which is y=0=bottom. (Edit: For events, that is. Quartz 2D, the drawing API, uses unflipped coordinates, the same as AppKit does.)

定格我的天空 2024-08-26 08:06:34

是的,使用主屏幕的高度是翻转屏幕坐标的标准方法。

Yes, using the main screen's height is the standard way of flipping screen coordinates.

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