如何存储(和使用)当前鼠标位置?
存储当前鼠标位置(系统范围)然后(稍后)将鼠标放在该存储点的最佳方法是什么?
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CGEventTap 来获取鼠标事件NSEvent 的。然后,您可以在活动到来时选择翻转或不翻转。
你的做法是错误的。 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.
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.)
是的,使用主屏幕的高度是翻转屏幕坐标的标准方法。
Yes, using the main screen's height is the standard way of flipping screen coordinates.