PyQT OSX Media Keys

2019-08-02 15:31发布

问题:

I'm creating a music player app with PyQT and I've defined a couple them as toolbar buttons. I can easily set the shortcut with setShortcut, but how can I set them to the OS X Media Keys? I already have iTunes disabled on launch so that's no problem. The music player Clementine has them also working when the application is not in focus, how can I have "global" hotkeys?

Many thanks!

Dennis

回答1:

Did you try:

QKeySequence(Qt.Key_MediaPlay)

and others from http://developer.qt.nokia.com/doc/qt-4.8/qt.html ?



回答2:

You only get global hot keys when you use the OSX native methods which seemingly change every minor release. An older example of this (i.e. doesn't work in Lion AFAIK) is available in libQxt

https://bitbucket.org/libqxt/libqxt/src/956e213e4f2d/src/gui/qxtglobalshortcut_mac.cpp