7

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?

1
  • xbindkeys solution below doesn't work for me, while easystroke seems overkill for my case. But this solution from Unix&Linux works for me, it is subjectively simpler.
    – fikr4n
    Sep 22, 2022 at 6:44

5 Answers 5

4

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

1
  • 3
    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, 2013 at 15:30
2

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.

2
  • 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, 2010 at 10:41
  • while xinput query-state <device name> | grep -Flq 'button[9]=down' should do the trick.
    – Dennis
    Oct 7, 2013 at 15:46
1

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.

1
  • 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, 2010 at 10:37
0

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

1
  • 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, 2010 at 6:41
0

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

You must log in to answer this question.