I have a Logitech M720 Mouse that I'm hoping to bind the side button (usually page forward) to the middle click button - something that I've done on my Windows with Logitech Options.
After researching, I've found that I will need to do it via xbindkeys
and xautomation
.
I tested out the key presses with xev
and found that the side button is button 9
, and middle scrollwheel button is button 2
.
I then made my .xbindkeysrc
file as such:
"xte 'mouseclick 2'"
b:9
However after repolling the rc file on xbindkeys
, the key bind is not recognised anywhere on my system, and doing an xev
test returns a peculiar result:
USUALS RESULT ON DEPRESSING BUTTON 9
ButtonPress event, serial 37, synthetic NO, window 0x4a00001,
root 0x1dd, subw 0x0, time 38400097, (160,106), root:(160,169),
state 0x0, button 9, same_screen YES
ButtonRelease event, serial 37, synthetic NO, window 0x4a00001,
root 0x1dd, subw 0x0, time 38400237, (160,106), root:(160,169),
state 0x0, button 9, same_screen YES
RESULTS AFTER XBINDKEYSRC FILE MODIFICATION (BUTTON 9)
KeymapNotify event, serial 37, synthetic NO, window 0x0,
keys: 4294967261 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
even after clearing out my .xbindkeysrc
file, the output is still the same, and will only return to normal after i killall xbindkeys
and restart by typing xbindkeys
in the terminal.
I found this this thread with a potential solution but unfortunately did not work for me.
Binding the button press to anything else for example "xte 'key a'"
works as expected.
Anyone with any pointers what I might be doing wrong?
Cheers.
xbindkeys
I think that you need a third line for each of your shortcuts. Maybe it's not a must, but I'm looking at the examples I have set up:
So, each of my entries has a third line, which defines the shortcut. Also, we have to release the pressed keys ourselves, and typically before the command we run. This is further complicated with Shift, as I've found releasing Shift causes problems.
xmodmap (user specific)
Typically,
xbindkeys
is used for complicated bindings, or to run scripts/commands. You could givemodmap
a try, which might be closer to the core of what you're trying to accomplish. Usingxev
, orevtest
, you can determine the Key Code that is used by the mouse, and then tell X to interpret it as another Key Code.~/.Xmodmap
~/.xinitrc
This tells X how to handle Key Code 97 (random, non-mouse) when pressed normally, or with modifiers (Shift, Alt, etc). You'd have the mappings in
~/.Xmodmap
and load it via$ modmap ~/.Xmodmap
, typically alongside X, so in~/.xinitrc
.evtest
is 'better' thanxev
in that it will help you to find the device you want to test, vs make you fumble around the system finding it in the/dev
lists.udev (system-wide)
Another solution is to use
udev
/evdev
, and to have the system perform this translation, regardless of if/when you start X, and with each connection of the device. This is a bit more complicated, but once you get used to some settings, you can work to migrate them here.Custom rules are places in
/etc/udev/hwdb.d/
This is the hardware database [configuration] directory. These are loaded in order, so files are normally prefixed with two digits, but this only matters when later rules overwrite earlier rules. This is a list of devices, by USB bus, device and vendor IDs. This method is ideal because you can remap keys for a specific keyboard, and not all keyboards./etc/udev/hwdb.d/99-myMouse.hwdb
This example finds two input devices, on the same USB bus, and from the same Vendor, but with different IDs. Both map Key Code 210 to the Menu button. You can learn to remap the keys on your mouse this way as well.
The system will have
hwdb
files in another directory,/usr/lib/udev/hwdb.d
. These files should not be edited, but you can use them as examples to help along the way.After making changes, the database needs to be updated: