Configure Extra Mouse Buttons on Linux (Ubuntu, Manjaro, Arch).(Logitech Trackball M570)
When you have extra tools or let's say extra buttons you will think about customizing their action.
In Linux, you are in full control when it comes to customization. However, sometimes it's difficult to find the answer or an easy pathway, as required customization becomes specific.
I have been using Logitech M570 Wireless Trackball mouse for the last few years, on my MacBook Pro and my Linux machines.
While in macOS it's easy through an application to customize the back and forward buttons to switch applications and open the Launchpad, In Linux, it requires digging deep and finding the right tools to do the job.
Here in this tutorial, I will explain how to configure extra mouse buttons to lunch my activity screen and display gnome application launcher.
But first, let's review some mice with extra buttons that you can customize:
- Logitech Wireless Trackball M570
- Logitech MX Master 3
- Logitech MX ERGO
- Logitech M720 Triathlon
- Logitech Marathon Mouse M705
- Logitech M585 Multi-Device
- Logitech MX Vertical Wireless Mouse
- Anker Wireless Ergonomic Mouse
- AmazonBasics Ergonomic Wireless PC Mouse
Now let's start oo customize the extra mouse buttons, In the begging we need to install 3 programs:
xbindkeys
xbindkeys is a tiny wrapper for Xorg's xev that reports key-codes.xdottool
xdottool is a lightweight system utility which simulates or fake keyboard and mouse inputs.xorg xev
The "xev" program is small utility for Xorg that retrieve the mouse and keyboard events.
Let's install the apps on Manjaro:
$ sudo pacman -Syu xbindkeys xorg-xev xdotool
Now let's find the key-codes for the extra buttons we need to configure, here we will use: xev
.
By clicking on the Event Tester window, You can get the mouse key-codes but using clicking on them. In my case it was 8 and 9.
Now, after getting the button codes we need to configure their actions, and we can do that with: xbindkeys
and xdotool
.
But first we need to run xbindkeys
with the default configurations:
xbindkeys -f ~/.xbindkeysrc
Then let's open the configuration file and add our new shortcuts which will basically simulate keyboard buttons.
.xbindkeysrc
# Mouse Button #8
# Show Gnome overview
"xdotool key super"
b:8
# Mouse Button #9
# Show all applications
"xdotool key super+a"
b:9
Finally, restart xbindkeys
killall xbindkeys
xbindkeys -f ~/.xbindkeysrc
Please note that you can customize the buttons to any shortcut you require, like taking a screenshot, lock the screen, switch to different keyboard layout, run commands (Alt + F2), or switch applications.
Also, you may consider using xte
tool itself instead of xdotool
to configure your shortcuts, or even another tool called xvkbd
There are some GUI-based tools worth mentioning, Piper which does not work at all, and EasyStroke Gesture Recognition which is very useful creating mouse gestures with custom actions.
If you have any comment or addition to this post, please send us a message.
Resources
- Arch Linux Wiki: Keyboard input https://wiki.archlinux.org/index.php/Keyboard_input
- xdotool https://www.semicomplete.com/projects/xdotool/
- How can I map keyboard buttons to my mouse buttons?
- xdotool keycode: https://gitlab.com/cunidev/gestures/-/wikis/xdotool-list-of-key-codes
- EasyStroke
- Useful answers: https://superuser.com/questions/883782/how-do-i-properly-map-a-keyboard-key-to-a-mouse-button