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?


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.

|improve this answer|||||
  • 2
    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 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.

|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

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 &"

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.

|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.

|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

there is a duplicate question: Map Ctrl and Alt to mouse thumb buttons

so here's a copy of answer from this question, using Easystroke:

i found a working solution here. it uses Easystroke (sudo apt install easystroke). kudos to @stuartr from ubuntuforums!

though there was one issue - re-mapped mouse click sporadically fired an original ('back' in my case) event. to avoid this, mouse button can be remapped to some unused number with xinput set-button-map (sudo apt install xinput). i've put this into my .xsessionrc (taken from this answer by @Maxim):

mi_mouse_id=$(xinput | grep 'GTech MI wireless mouse.*pointer' | sed 's/.*\tid=\([0-9]*\)\t.*/\1/')
xinput set-button-map $mi_mouse_id 1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 20

this maps mouse button 8 to button 20. hopefully button 20 has no meaning. at least it has absolutely no effect for me. now it's time to re-map button 20 to Ctrl:

  1. Preferences tab: additional buttons -> add -> radio button 'Instant Gestures' -> click the mouse button of choice in the grey area (for me a 'back, thumb button' became '(Instantly) Button 20')
  2. Preferences tab: Select 'Autostart Easystroke'
  3. Actions tab: Add Action
     Name: anything you like (e.g. 'Mouse 20 -> Ctrl')
     Type: 'Ignore'
     Details: click it once to change 'Ignore' to 'Key combination...'. then press Ctrl + a. 'a' doesn't matter and is ignored. 'Key Combination' will be replaced with 'Ctr'
  4. With the new action selected/highlighted -> click 'Record Stroke' -> press the mouse button you're wanting to use again (this came up with '20 -> 20' in the Stroke column for me)
  5. Now pressing and holding my mouse button brings up a dinky 'Ctr' on the screen and acts like the button is being held for as long as the mouse button is
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy