开发者

Cocoa/Carbon: catch global hotkey when key is kept pressed (held down)

Using Install开发者_如何学编程ApplicationEventHandler and RegisterEventHotKey from Carbon framework, I'm able to catch whatever key I want.

On the contrary I can't find a way to handle correctly the event when a key is held down (kept pressed). I mean, when I held down a key, RegisterEventHotKey responds like if I have pressed and then released the key; I want it, instead, to send the "event" continuously until the key is released.

What I really want to achieve, to be precise, when a key is kept pressed is this:

as soon as the key is pressed and held down I want that InstallApplicationEventHandler and RegisterEventHotKey create an event but not only once (as I have now) but every x milliseconds or so until the key is released.

The particular keys that I'm considering are not modifier keys.

Can you help me? I'm really becoming crazy on this!


You need to use an event tap; RegisterEventHotKey isn't flexible enough to do what you want. Check out Event Taps Testbench and the documentation.


Maybe start firing a timer every 0.25 seconds or something that checks to see if the appropriate keys are still down. If they are, re-invoke the action. Otherwise, invalidate the timer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜