HOW TO: Multimedia and Extra Mouse Buttons on Linux

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by omniuni »

Hi All,
I've spent the last few minutes...hours... trying to get all my multimedia keys and mouse buttons doing what I wanted them to do. Since I could not find a good tutorial, here it is.

An Easy (well, sort of) Way to get Multimedia Keys and Extra Mouse Buttons Doing What You Tell Them To Do In Linux, by OmniUni

Useful Commands
xev -name GetKeys - Display a little box that monitors all input. Good for finding your mouses button numbers.
xbindkeys -k - Display a little box which you can highlight and press a key in to find out what it's called. Works for your keyboard.
xmodmap [file name] - modify or create keys. I'll get to this later
xbindkeys -f [file name] - pass a file into xbindkeys, and bind the keys to commands
xdotool - simulate a key press, you'll want this with your mouse

You should be able to install any/all of these with your Linux distribution's package manager.

Getting Started
Use xbindkeys and xev as mentioned above to get information about your extra keys. For example, after running xev, I was able to find the following:
ButtonPress event, serial 31, synthetic NO, window 0x4c00001,
root 0x8b, subw 0x0, time 87128220, (95,156), root:(1520,207),
state 0x0, button 1, same_screen YES
Which tells me the name of the mouse button I just pressed, "button 1". It turns out that the buttons on the side of my mouse are 8 and 9.

Doing Something

Now, the problem is that buttons 7 and 8 are currently useless for me to really do much with. I can configure KDE to do things with keyboard combinations, but I can't specify mouse buttons. Wouldn't it be nice if they just showed up as extra function keys?

Luckily, we can create new keys in Linux! Create a file, let's say, .Xmodmap in your home folder. Add something like the following:

Code: Select all

keycode 1000 = F14
keycode 1001 = F15
You can now make keys F14 and F15 exist by running
xmodmap .Xmodmap
Now, we just need to bind those mouse buttons to F14 and F15. This is where xbindkeys comes into play along with our button numbers we found earlier. Create a file, say .xbindkeysrc in your home folder. Give it contents like this:

Code: Select all

"xdotool key F14"
  b:8
 
"xdotool key F15"
  b:9
Notice that I'm using b:8 and b:9 to refer to the mouse buttons 8 and 9 that I found earlier. Also notice that the line above is a command to run. I am using xdotool to press the new F14 and F15 keys that I created with xmodmap. I also found that the mail button on my keyboard is called XF86Mail, and since I don't use it, I'm going to make it run Amarok. After all my configuration, then, my .xbindkeysrc looks like this:

Code: Select all

"xdotool key F14"
  b:8
 
"xdotool key F15"
  b:9
 
"amarok"
 XF86Mail
 
I can apply this file, by running the command:
xbindkeys -f .xbindkeysrc
Wrapping it Up

That wasn't too bad, was it? Now, you can bind your keyboard keys to commands, and you can make your mouse buttons press random function buttons that didn't previously exist! Use your desktop environment's keyboard shortcut tools to make your new F14 and F15 (and maybe more) keys actually do things. Of course, if you just want to do things like adjust volume, you can bind your mouse keys to some of the existing XF86 keys that already may work, such as XF86AudioLowerVolume, XF86AudioRaiseVolume, or others which you can find here: http://wiki.linuxquestions.org/wiki/XF8 ... rd_symbols.

Make it Work Forever (Execute Commands on Login)
For KDE users, create a file, say, makekeys.sh in your ~/.kde/Autostart folder, make it executable, and put in the commands to run like this:

Code: Select all

xmodmap ~/.Xmodmap;
xbindkeys -f ~/.xbindkeysrc;
If you want to give me instructions for other desktop environments, let me know and I'll add it here.


Let me know how that works for you, and may your programming productivity improve with this help!
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by omniuni »

Erm.... I was just wondering... did this help anyone?
eliasv
Forum Newbie
Posts: 1
Joined: Fri Jun 26, 2009 8:02 am

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by eliasv »

yes thank you this was extremely helpful :). I can't believe nobody else has said so yet so i created an account just to let you know :D.
cheers.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by omniuni »

Thank you, Eliasv! That's great to hear. This is a great forum, anyway, welcome! Let me know if you have any other little Linux questions.
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by Doug G »

I enjoyed the information also, even though I didn't have any immediate use for any of it. Thanks for the effort!

I don't know if it's OT or not, do you know where I can find the specifics about how my synaptics touchpad buttons are set? I'm using Fedora 9, and ever since a synaptics driver update many months ago the right-click button does different things than what it should. Intermittently. The laptop dual boots and the touchpad works flawlessly in XP, I don't think there is any hardware issue.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by omniuni »

That is indeed odd. My Synaptics pad works just fine. What distro are you using? Also, you can use the tool mentioned above to right-click and see what signal is being sent.
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by Doug G »

I'm using Fedora 9
And it's a Dell inspiron 1200 old cheap laptop. I will spend a little time with the tools you've mentioned and see what I can figure out, thanks.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: HOW TO: Multimedia and Extra Mouse Buttons on Linux

Post by omniuni »

You may want to try updating your Fedora. I have a lappy with F10, and it works just fine. Perhaps it was just an F9 bug.
Post Reply