openfrog
openfrog

Reputation: 40735

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 take 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?

Upvotes: 0

Views: 293

Answers (1)

sbooth
sbooth

Reputation: 16966

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.

Upvotes: 1

Related Questions