Define additional shortcut keys without overwriting existing shortcuts

My laptop keyboard does not have media shortcut keys (e.g. "Next Track", etc). I frequently use the laptop connected to an external keyboard, which does. I go to Settings->Keyboard->Shortcuts tab, and select "Sound and Media", and I see that "Next Track" is bound to the shortcut key "audio next". I see that I can replace this with a custom key binding, but it overwrites the "audio next" shortcut.

I'd like a solution that allows me to map a second shortcut to this command without overwriting it. I see that I can define custom keys, so I could make a unique mapping for rhythmbox-client --next, etc, but that would be a solution specific to rhythmbox. I'm looking for a more native Ubuntu solution that will work in any player the same way the current "audio next" media keys do on my external keyboard. Any ideas?


To simulate keyboard events I suggest you the great tool xdotool Install xdotool.

1. Install xdotool via terminal (CTRL+ALT+T):

sudo apt-get install xdotool

or use the Software Center Install xdotool.

2. Create a script that uses xdotool to emulate the "audio next" event from multimedia keyboards. In the terminal:

mkdir -p ~/bin  
gedit ~/bin/audionext

Copy the following content into the editor window that opened up. After copying the code save, then close it:

#!/bin/sh
sleep 0.3  
exec /usr/bin/xdotool key XF86AudioNext  
EOF

Now make the script executable:

chmod +x ~/bin/audionext

3. Log out and log in to reload your PATH.

4. Create the custom shortcut

Go to System Settings, then go to Keyboard, then Shortcuts.

Press the + button at the bottom of the dialog. Provide a name for the shortcut you're about to create and for the command fill in: audionext. Press OK.

Next to your new shortcut you will see disabled. Click on that text and then press the keyboard combination you want to be assigned to your media keyboard emulation.

You should now be able to "audio next" with your keyboard shortcut!