This question has already been asked but was never answered properly. After clearance with @Seth I am now asking it again. This will allow me to respond and possibly modify the question a lot easier. The original question can be found here:
Map Ctrl and Alt to mouse thumb buttons
Issue:
Though it is very simple to map any keystrokes to a mouse button using xbindkeys
in conjunction with xdotool
or xte
it seems a lot more problematic to map a modifier key (e.g. ALT, CTRL, SHIFT etc.) to it.
The final soloution should allow i.a. a CTRL + click (e.g. for selecting multiple entries of a list) with just the mouse.
A couple of possible approaches to solve this can be found here at Stack Exchange as well as at other Linux related forums. But none of those work as expected as they lead to other issues and side effects.
Notes:
Some of the examples below involve Guile with Scheme syntax and rely on .xbindkeysrc.scm
file whereas others rely on the .xbindkeysrc
file with its respective syntax. I am aware that they won't work together.
Furthermore the below snippets rely on xdotool
only but I am open to approaches involving other applications like e.g. xte
as well - though it seems both lead to the same results and therefore I am using just xdotool
actions here.
Approach A:
Updating the .xbindkeysrc
file with:
"xdotool keydown ctrl"
b:8
"xdotool keyup ctrl"
release + b:8
That's what I initially tried but it has the side-effect that the modifier is being held and can not be released.
Approach B:
Updating the .xbindkeysrc.scm
file with:
(xbindkey '("b:8") "xdotool keydown ctrl")
(xbindkey '(release "b:8") "xdotool keyup ctrl")
(xbindkey '("m:0x14" "b:8") "xdotool keydown ctrl")
(xbindkey '(release "m:0x14" "b:8") "xdotool keyup ctrl")
Found at http://www.linuxforums.org/forum/hardware-peripherals/169773-solved-map-mouse-button-modifier-key.html and tries to address the issue where the modifier is being held (as described at approach a).
Though it fixes that it does only work partially as it is not possible to perform other mouse clicks while the thumb button is pressed.
Approach C:
Updating the .xbindkeysrc
file with:
"xdotool keydown ctrl"
b:8
"xdotool keyup ctrl"
release + control + b:8
Tried out by OP of the linked question here at askubuntu. A lot simpler and more solid as it does not involve modifier states. Nevertheless the issue remains, i.e. a CTRL + click is not possible.
It seems that xbindkeys
itself is the problem here as it recognizes the click but won't execute it. This can be tested using xev | grep button
and xbindkeys -v
:
A normal mouse click as recorded by xev
should look like:
state 0x10, button 1, same_screen YES
state 0x110, button 1, same_screen YES
As well as for the thumb button:
state 0x10, button 8, same_screen YES
state 0x10, button 8, same_screen YES
But when having the above xbindkeys
configuration enabled it does not record anything. Though it makes sense for the thumb button as it is mapped to CTRL and therefore is not a mouse button anymore it is strange that button 1 is not recorded as well. This is likely because xbindkeys
does not execute it but itself is recognizing it:
Button press !
e.xbutton.button=8
e.xbutton.state=16
"xdotool keydown ctrl"
m:0x0 + b:8 (mouse)
got screen 0 for window 16d
Start program with fork+exec call
Button press !
e.xbutton.button=1
e.xbutton.state=20
Button release !
e.xbutton.button=1
e.xbutton.state=276
Button release !
e.xbutton.button=8
e.xbutton.state=20
"xdotool keyup ctrl"
Release + m:0x4 + b:8 (mouse)
got screen 0 for window 16d
Start program with fork+exec call
Approach D:
Updating the .xbindkeysrc
file with:
"xdotool keydown ctrl"
b:8
"xdotool keyup ctrl"
release + control + b:8
"xdotool click 1"
b:1
Just too simple ... but leads to an infinite loop of clicks.
UPDATE:
In the meantime I've bought a Logitech G502 and noticed that once configured via the driver on Windows not only the profile itself is stored on the device memory but the actual keypress is done by the mouse. That in fact solved my problem on Linux!
The only other mouse I remember that was able to do that was the Razer Copperhead back in the days. But I guess there are other mice available today which can do the same.