Search code examples
c++macosqtkeyboard-shortcuts

OS X Global Shortcuts in C++


I am currently working on a QT application (in C++) that lives in the system tray, and requires a global shortcut. Currently it does not seem as though QT provides a way to register global shortuts with the OS. I've located Qxt (http://libqxt.org), however for various reasons this library will not suffice.

Therefore, I am looking for a way to register a global shortcut within OS X, so that even if my application does not have focus (remember it's in the system tray!) that I can still interact with its functionality.

Any ideas how to accomplish this?


Solution

  • There's RegisterEventHotKey (Carbon). A thorough write up can be found here.

    You could also install a CGEventTap. This is slightly more complex to write, but still quite short. A demo can be found here.