Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Microsoft Sidewinder X8 mouse and I wish to use 8 for Shift and the 9 for Control. Can anybody please tell me how?

share|improve this question

Install xdotool and xbindkeys

sudo apt-get install xdotools xbindkeys

Then copy the following code into ~/.xbindkeysrc

"xdotool keydown shift"
"xdotool keyup shift"
        release + shift + b:9
"xdotool keydown ctrl"
"xdotool keyup ctrl"
        release + control + b:8

where b:x is the number of your button which you can find out using xev. As I don't want this bindig permanent everytime I need it I start a terminal and type xbindkeys -n. When I don't need it anymore I simply close the terminal.

share|improve this answer
That works well as far as mapping a button to a key goes. Sadly, it prevents the second mouse from getting recognized while the first one is held down. – Dennis Oct 7 '13 at 15:30

First install xdotool

sudo aptitude install xdotool

Then, you can create a script to simulate a Ctrl key press. Open gedit and copy paste the following:

#! /bin/bash

xdotool keydown ctrl

while [MOUSEKEYDOWN == 1]; do  #TODO change the while test.
sleep 30 
   #decrease sleep if script doesn't react fast enough on releasing the key, 
   #increase sleep if the computer uses to many CPU when pressing the button.

xdotool keyup ctrl # Lift the key back up after no button is pressed.

I'm not a great bash programmer. I need to search a way to identify if your button is down and I may have (more than one) syntax errors but I guess a bash programmer gets the idea.

If someone fixed the script, save it under and make it executable

chmod +x

Then, as nathwill said, go to system -> preferences -> keyboard. Add a custom command, choose to add the ~/ command and press your mouse button as shortkey.

This should do it.

share|improve this answer
The xdotool package looks like a promising direction but this isn't quite a full solution yet. Has somebody figured out how to use it to properly to detect mouse down / up events and trigger the desired modifier key equivalents? – Caleb Oct 15 '10 at 10:41
while xinput query-state <device name> | grep -Flq 'button[9]=down' should do the trick. – Dennis Oct 7 '13 at 15:46 explains how to accomplish this using xbindkeys and xmacroplay (from the xmacro package). Both of these applications are available from the Ubuntu repositories.

Here is an example from the site that explains how to map mouse button 6 to the Alt + Left key combination.

Put this in ~/.xbindkeysrc , and pressing mouse button 6 will echo the Alt + Left key combination to the X server, which maps to "back" in Konqueror and Mozilla :

"echo -e 'KeyStrPress Alt_L\nKeyStrPress Left\nKeyStrRelease Left\n KeyStrRelease Alt_L' | xmacroplay &"

There is Shift_L and Control_L (as well as Shift_R and Control_R if you prefer the right versions of the keys instead of the left versions). Simply substitute these keys into the above command, change b:6 to be the actual mouse button you want to map to the key, and put the command in ~/.xbindkeysrc, and you should be all set.

share|improve this answer
The xmacro package was last updated in 2001. It does not compile on all distros (non Ubuntu here) any more due to major changes in the X system in the last nine years. Is there not another solution for this? – Caleb Oct 15 '10 at 10:37

SystemPreferencesKeyboard shortcuts lets you map keys/buttons to commands; if that doesn't work xbindkeys is another great application for key mapping.

share|improve this answer
I know this works to bind a mouse click to a key event, but I've never gotten it to work as a modifier key. Do you have an example config that actually assigns shift/ctrl etc to a mouse event? – Caleb Oct 12 '10 at 6:41

Your Answer


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