Page 1 of 1

HOW TO: Multimedia and Extra Mouse Buttons on Linux

Posted: Wed Feb 11, 2009 1:27 am
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!

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

Posted: Fri Mar 06, 2009 11:07 pm
by omniuni
Erm.... I was just wondering... did this help anyone?

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

Posted: Fri Jun 26, 2009 8:05 am
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.

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

Posted: Fri Jun 26, 2009 3:17 pm
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.

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

Posted: Sun Jun 28, 2009 1:35 am
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.

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

Posted: Sun Jun 28, 2009 4:13 pm
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.

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

Posted: Sun Jun 28, 2009 4:20 pm
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.

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

Posted: Sun Jun 28, 2009 4:47 pm
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.