如何使用 Quartz 事件处理鼠标单击?
我有一个 CGEventTap ,我想观察和处理所有系统鼠标单击事件。检测鼠标单击事件很容易,但我不希望系统的其余部分处理某些单击。我不知道怎么办。
系统仅发送低级事件,例如 mouseUp
、mouseDown
、mouseDragged
等。当我收到 mouseDown
事件时,我不知道它是否是鼠标单击的一部分,也可能是拖动事件。我必须等待以下事件 - 如果它是 mouseUp
,我就会单击。但是,如果我想自己处理点击并防止它进入事件队列的其余部分,我不能简单地窃取 mouseUp
事件,就像之前的 mouseDown
已发送。
我以为我可以延迟 mouseDown
事件,只在收到相应的 mouseUp
后才发送它,但这感觉不对,我不想延迟所有系统 mouseDown
事件只是因为我的应用程序。我错过了什么吗?
I have a CGEventTap
and I would like to observe and process all system mouse click events. Detecting a mouse click event is easy, but I don’t want some of the clicks to get processed by the rest of the system. And I can’t figure out how.
The system only sends low-level events like mouseUp
, mouseDown
, mouseDragged
and so on. When I receive a mouseDown
event, I don’t know if it’s a part of a mouse click yet, could be a drag event. I have to wait for the following event – if it’s a mouseUp
, I have a click. But if I want to process the click myself and keep it from going down the rest of the event queue, I can’t simply steal the mouseUp
event, as the previous mouseDown
was already sent.
I thought I could delay the mouseDown
event and only send it later after receiving the corresponding mouseUp
, but that feels wrong, I don’t want to delay all system mouseDown
events just because of my application. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你所想的其实是对的。您必须将鼠标按下事件推迟等于鼠标双击速度,应该在 100-500 毫秒左右。例如,用户不会注意到 100 毫秒的延迟。理想情况下,您应该使用 Mac OS X 鼠标设置中的值,以获得良好的用户体验。
What you thought is actually right. You have to postpone mouse down event for the time interval equal to a mouse double click speed, that should be around 100-500 milliseconds. User will not notice a 100 millisecond delay, for example. Ideally, you should a value from Mac OS X mouse settings to make a good user experience.