如何使用Quartz事件处理鼠标单击? [英] How do I process a mouse click using Quartz events?
问题描述
我有一个CGEventTap
,我想观察并处理所有系统鼠标单击事件.检测鼠标单击事件很容易,但是我不希望系统的其余部分处理某些单击.而且我不知道怎么做.
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.
系统仅发送低级事件,例如mouseUp
,mouseDown
,mouseDragged
等.收到mouseDown
事件时,我不知道它是否是鼠标单击的一部分,可能是拖动事件.我必须等待以下事件-如果是mouseUp
,请点击.但是,如果我想自己处理点击并阻止其继续进入事件队列的其余部分,我就不能简单地窃取mouseUp
事件,因为先前的mouseDown
已发送.
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.
我以为我可以延迟mouseDown
事件,并且只在收到相应的mouseUp
之后才发送它,但这感觉不对,我不想因为我的应用而延迟所有系统mouseDown
事件.我想念什么吗?
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?
推荐答案
您认为正确的内容.您必须将鼠标按下事件延迟等于鼠标双击速度,则应为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.
这篇关于如何使用Quartz事件处理鼠标单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!