What commands are invoked when I press my media keys (play / pause, next, previous)?

I had a look at simulate media keys in the terminal, and my requirement is the same, except I cannot use the approach in the answer. The answers simulates the keys themselves using xdotools, which I cannot do because I have re-mapped what these keys do. What I want to know is the underlying mechanism in the OS which sends messages to apps which need to know multimedia keys are pressed. I suspect it may be related to dbus.


I had to re-map my media keys (play / pause, next, previous) to other commands this link contains some background.

I did this by removing the previous key-bindings for these media keys and re-assigning them in settings > keyboard > shortcuts.

I want to know the original command so that I can invoke spotify-command ; original-command on the keypress instead of just invoking spotify-command.

  • in Gnome I mean Ubuntu 18.04 18.10 19.04 19.10 I have installed Spotify but Multimedia keys worked out of the Box... are the media keys working for other AV apps?? – UnKNOWn Oct 27 '19 at 7:29
  • This is for unity, 16.04. If you want background on keys not working, have a look at the linked question. – Peeyush Kushwaha Oct 27 '19 at 7:40
  • I have gone through the link briefly.. I understood that you want 3 commands with dbus which are available in the link.. have you tried those? – UnKNOWn Oct 27 '19 at 7:42
  • are your multimedia keys working for other Audio Video Apps under Unity?? – UnKNOWn Oct 27 '19 at 7:42

when you press Multimedia Keys, they have keysymbols which can be known with the command xmodmap -pke | grep Audio


$ xmodmap -pke | grep Audio
keycode 121 = XF86AudioMute NoSymbol XF86AudioMute
keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 171 = XF86AudioNext NoSymbol XF86AudioNext
keycode 172 = XF86AudioPlay XF86AudioPause XF86AudioPlay XF86AudioPause
keycode 173 = XF86AudioPrev NoSymbol XF86AudioPrev
keycode 174 = XF86AudioStop XF86Eject XF86AudioStop XF86Eject
keycode 175 = XF86AudioRecord NoSymbol XF86AudioRecord
keycode 176 = XF86AudioRewind NoSymbol XF86AudioRewind
keycode 198 = XF86AudioMicMute NoSymbol XF86AudioMicMute
keycode 208 = XF86AudioPlay NoSymbol XF86AudioPlay
keycode 209 = XF86AudioPause NoSymbol XF86AudioPause
keycode 215 = XF86AudioPlay NoSymbol XF86AudioPlay
keycode 216 = XF86AudioForward NoSymbol XF86AudioForward
keycode 234 = XF86AudioMedia NoSymbol XF86AudioMedia

from the link you provided, these commands should work for your Custom Keyboard Shortcuts

enter image description here

for Play/ Pause

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

for Next

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next

for Previous

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous

for Stop

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop

for Play

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play
  • Thanks for the reference to xmodmap. After the key is pressed, I believe it's up to the OS to execute a command associated with the key. Can you shed some light on what command is executed by ubuntu/unity when say XF86AudioNext key is pressed (without any custom configuration)? – Peeyush Kushwaha Oct 29 '19 at 6:48
  • Hi.. I think its difficult to know at my knowledge.. are you not looking for above dbus commands? – UnKNOWn Oct 29 '19 at 6:54
  • Nope, that's already clear from the spotify question I linked to. – Peeyush Kushwaha Oct 29 '19 at 6:55
  • yes.. I guess its the same command that will use by XF86 without spotify in the line dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify....... similarly – UnKNOWn Oct 29 '19 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.