Most desktop environments already have a daemon to deal with so-called multimedia hotkeys, but I use plain Openbox, hence the clunky title.
Test your setup with xev1:
KeyPress event (...) keycode XX (keysym 0xXXXX, <KeyName>) (...)
(take note of <KeyName> and/or keycode XX)Multimedia keys are not just on your keyboard. Also try wired or wireless peripherals - my bluetooth speaker sends the appropriate key presses when I press its Play/Pause button. The system just doesn’t pick them up - yet - that’s what this article is about.
I found this great tutorial and adapted it slightly to my own situation.
The main actor is the playerctl application. It’s in the Arch repositories and probably most other distros’, too.
Just install it; it’s not a daemon, it simply serves as a command line tool to send the appropriate command to any app that has registered itself on the MPRIS Dbus interface.
Please refer to this chapter of the original tutorial for a quick introduction.
Here’s a list of available commands (man playerctl):
Most media applications (Firefox, Chromium, VLC…) already support MPRIS, but my two favorites - MPV for video and MPD for audio - do not. Fortunately 3rd party daemons/plugins can provide MPRIS functionality for both.
Install mpDris2 (AUR package), start & enable the systemd user service.
Install the mpv-mpris plugin (repo package). MPV will load it by default.
Now we can add the playerctl commands we want to use to rc.xml. Example:
...
<keybinds>
...
<keybind key="C-A-Up XF86AudioRaiseVolume">
<action name="Execute">
<command>playerctl volume .03+</command>
</action>
</keybind>
<keybind key="C-A-Down XF86AudioLowerVolume">
<action name="Execute">
<command>playerctl volume .03-</command>
</action>
</keybind>
<keybind key="C-A-space">
<action name="Execute">
<command>playerctl play-pause</command>
</action>
</keybind>
<keybind key="XF86AudioPlay">
<action name="Execute">
<command>playerctl play</command>
</action>
</keybind>
<keybind key="XF86AudioPause">
<action name="Execute">
<command>playerctl pause</command>
</action>
</keybind>
...
</keybinds>
...
And openbox --reconfigure.