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.

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

4 Answers 4

Install xdotools and xbindkeys

sudo apt-get install xdotools xbindkeys

Then copy the following code into ~/.xbindkeysrc

"xdotool keydown shift"
        b:9
"xdotool keyup shift"
        release + shift + b:9
"xdotool keydown ctrl"
        b:8
"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. –  sudo 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.
done

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 ctrl.sh and make it executable

chmod +x ctrl.sh

Then, as nathwill said, go to system -> preferences -> keyboard. Add a custom command, choose to add the ~/ctrl.sh 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. –  sudo Oct 7 '13 at 15:46

http://linux.derkeiler.com/Newsgroups/comp.os.linux.x/2003-07/0010.html 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 &"
b:6

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

 
discard

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