How to configure extra buttons in Logitech Mouse
You're going to need several applications for this, to install them run
# Ubuntu 14.04 and newer
sudo apt-get install xbindkeys xautomation x11-utils
or
# Before Ubuntu 14.04
sudo apt-get install xbindkeys xautomation xev
(xev
was merged into x11utils, as of Ubuntu 14.04 or greater)
Step 1
You need to find the button numbers for the buttons on your mouse. Run xev
. You will see a litle white windows appear, put your mouse in it and press your mouse buttons (it's best to do this one button at a time). You should get output like this for each button:
ButtonRelease event, serial 41, synthetic NO, window 0x4c00001,
root 0x2e9, subw 0x4c00002, time 25804905, (31,28), root:(821,80),
state 0x110, button 1, same_screen YES
(note: xev
also capture mouse movement so you might need to sift through mouse movement events to find your button events; e.g.: xev -event mouse | grep Button --before-context=1 --after-context=2
)
This is what is important from that output: button 1
. That tells us that particular button is button one. I would store this in a .txt
file for now.
Step 2
Create the xbindkeys
config file using:
xbindkeys --defaults > $HOME/.xbindkeysrc
Next we need to add the key/button bindings to the config file. You can open this file with gedit $HOME/.xbindkeysrc
. This is where the fun begins. We are going to use xte
to set bindings to our buttons.
To make a button act as Ctrl we would add:
"xte 'key Control_L'"
b:1
This would bind Ctrl to mouse button one.
If you will tell me the button numbers of your buttons and what you want each to do, I will write the script for you.
I followed the @Seth's instructions, but the binding I wanted was to for the thumb button an the M705 to do CTRL + Left-click
(for opening links in a new tab in chrome browser). The binding I needed to add was this:
"xte 'keydown Control_L' 'mouseclick 1' 'keyup Control_L'"
b:10 + Release
It waits for the thumb button to be released, and then presses control key, performs the mouse click, then releases the control key.
For anyone who wants to bind copy and paste actions to mouse buttons:
- Follow Seth answer (the one with Step 1, Step 2 and
sudo apt-get install xbindkeys xautomation xev
) - Put following lines in your
.xbindkeysrc
file:
This is for copying:
"xte 'keydown Control_L' 'key c' 'keyup Control_L'"
b:9
This is for pasting:
"xte 'keydown Control_L' 'key v' 'keyup Control_L'"
b:8
*b:9
means button 9 on the mouse (check button numbers with xev
)
- It won't work right away, you must reload
.xbindkeysrc
first or restart your machine.
The best answer in 2021 is the Key Mapper utility:
https://github.com/sezanzeb/key-mapper
No more hacking required.