jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
543 stars 68 forks source link

Queston: Capture keys without mpv being in focus #157

Closed jonnieey closed 3 years ago

jonnieey commented 3 years ago

Is there a way to bind a key and use it globally without the focus being on mpv interface. For example , bind F2 to pause playback and do it while the focus is another program. Similar to XF86 buttons?

jaseg commented 3 years ago

I don't think mpv has one built-in. That means python-mpv also won't help you there.

For Qt apps, the independent QHotkey library seems to be a good solution. For other UI toolkits, there is a system_hotkey python package that seems like it will do the thing on Windows and linux (no OS X). The pynput python package seems to be an alternative that will work on all three platforms.

In case you don't need to ship this to other users and you don't want to deal with that complexity, you could also just set up a hotkey in an external hotkey manager like AutoHotkey (on Windows) or the one usually built-in to Linux DEs like KDE or Gnome (look in your system settings under keyboard settings). That hotkey could then just call a script that messages mpv/your app e.g. through a named pipe that something's going on.

I hope that helps, have a nice day :)

jonnieey commented 3 years ago

Cheers. I'll look into suggested solutions. Have a nice day too. :thumbsup: