HOW TO: Multimedia and Extra Mouse Buttons on Linux
Posted: Wed Feb 11, 2009 1:27 am
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:
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:
You can now make keys F14 and F15 exist by running
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:
I can apply this file, by running the command:
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:
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!
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:
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.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
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 = F15Now, 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:xmodmap .Xmodmap
Code: Select all
"xdotool key F14"
b:8
"xdotool key F15"
b:9Code: Select all
"xdotool key F14"
b:8
"xdotool key F15"
b:9
"amarok"
XF86Mail
Wrapping it Upxbindkeys -f .xbindkeysrc
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;Let me know how that works for you, and may your programming productivity improve with this help!