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" 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.
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.
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.
there is a duplicate question: Map Ctrl and Alt to mouse thumb buttons
so here's a copy of answer from this question, using
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:
- 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')
- Preferences tab: Select 'Autostart Easystroke'
- Actions tab: Add Action
Name: anything you like (e.g. 'Mouse 20 -> Ctrl')
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'
- 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)
- 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