Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Were you able to solve your problem by following the steps in my answer? –  mrcktz Jan 15 '13 at 21:23
1  
Yup! I think the bounty didn't go through first time I clicked on it, thanks for following up. –  cboettig Jan 15 '13 at 22:59

1 Answer 1

up vote 3 down vote accepted
+50

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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