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.

Logitech M570 Wireless Trackball mouse (src: Logitech)

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:

  1. Logitech Wireless Trackball M570
  2. Logitech MX Master 3
  3. Logitech MX ERGO
  4. Logitech M720 Triathlon
  5. Logitech Marathon Mouse M705
  6. Logitech M585 Multi-Device
  7. Logitech MX Vertical Wireless Mouse
  8. Anker Wireless Ergonomic Mouse
  9. AmazonBasics Ergonomic Wireless PC Mouse

Now let's start oo customize the extra mouse buttons, In the begging we need to install 3 programs:

  1. xbindkeys
    xbindkeys is a tiny wrapper for Xorg's xev that reports key-codes.
  2. xdottool
    xdottool is a lightweight system utility which simulates or fake keyboard and mouse inputs.  
  3. 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

xte keys (man xte)

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

  1. Arch Linux Wiki: Keyboard input https://wiki.archlinux.org/index.php/Keyboard_input
  2. xdotool https://www.semicomplete.com/projects/xdotool/
  3. How can I map keyboard buttons to my mouse buttons?
  4. xdotool keycode: https://gitlab.com/cunidev/gestures/-/wikis/xdotool-list-of-key-codes
  5. EasyStroke
  6. Useful answers: https://superuser.com/questions/883782/how-do-i-properly-map-a-keyboard-key-to-a-mouse-button





Hamza Mu Author: Hamza Mu

A physician with programming skills, Linux user since late 1990s, Open source supporter. Coding with Python, NodeJS (Meteor, VueJS, Express, D3, PhantomJS), SmallTalk & R language.





Read more