开发者

How can my Cocoa app receive global keyboard events even if it doesn't have focus?

开发者 https://www.devze.com 2023-03-23 16:09 出处:网络
I\'m building a little app which needs to recognize if certain keys on the keyboard were pressed. In this case the arrow keys. The app must tak开发者_开发知识库e action when these keys get pressed, ev

I'm building a little app which needs to recognize if certain keys on the keyboard were pressed. In this case the arrow keys. The app must tak开发者_开发知识库e action when these keys get pressed, even if it's not the frontmost and has no focus.

Is this possible to do? What would I have to do to receive these keyboard events no matter where they happen?


You do this by registering a hotkey using Carbon's RegisterEventHotKey function. There are also open source libraries available that make this easier, for example SGHotKeysLib.

0

精彩评论

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

关注公众号