0

Background info:

I know how to use a keyPressEvent, it works fine when the window is in focus. My keyPressEvent function is as follows:

def keyPressEvent(self, e):
    if e.key() == Qt.Key_F7:
        self.prevSong()
    if e.key() == Qt.Key_F9:
        self.nextSong()

The keys are connected to the functions and they do what they are supposed to do

What I am trying to achieve:

Make the same key presses call the same functions when the key is pressed when the window is out of focus or in the background. How can I make this happen on a Mac?

chaNcharge
  • 239
  • 1
  • 2
  • 12
  • That is not handled by Qt, that is managed by the OS, so the solution will not be found in PyQt. You should look for a library that manages it but it depends on the OS where you are running your application. https://stackoverflow.com/questions/35564502/c-qt-global-hotkeys, Maybe the library can be: https://pypi.python.org/pypi/keyboard/ – eyllanesc Mar 13 '18 at 07:08
  • Possible duplicate of [How to create a global hotkey on Windows with 3 arguments?](https://stackoverflow.com/questions/16615087/how-to-create-a-global-hotkey-on-windows-with-3-arguments) – Skandix Mar 13 '18 at 22:20
  • That is for Windows, I'm on a Mac using PyQt5. I edited the post accordingly. @Skandix – chaNcharge Mar 14 '18 at 01:07
  • Possible duplicate of [system wide shortcut for Mac OS X](https://stackoverflow.com/questions/11347862/system-wide-shortcut-for-mac-os-x) – eyllanesc Mar 14 '18 at 01:19

0 Answers0