How can my Cocoa app receive global keyboard events even if it doesn't have focus?
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.
精彩评论