Bind Mouse Buttons to Keys or Scripts under Linux with xbindkeys and xvkbd

Xilin Sun
Xilin Sun
Jan 6, 2018 · 2 min read

So, I have bought this Logitech MX Ergo Plus wireless trackball and want to use it under Linux. All buttons work out of the box, but I want to customize some of them. On Windows there is Logitech software to do the rebinding job, while on Linux I can achieve more with xbindkeys and xvkbd. This should work for most mice and trackballs under X (probably not under Wayland).

Install software

Get button codes

Run xev in terminal, press one button on the mouse, and watch the console output. The button number can be found there. For example, here is the output for left button:

The left button is recognized as button 1.

Using the same method, I have got the codes for all the (usable) buttons on my MX Ergo:

I marked all these buttons in the picture below. The switching device button and precision button are not avilable for the operating system.

Bind buttons

By default, buttons 9 and 8 work as back and forward in the browser, but I think they will be more useful if working as tab switchers (Ctrl-PgUp and Ctrl-PgDn). Also, I want to bind buttons 6 and 7 as closing tab and new tab. To do this, I add the following part to my ~/.xbindkeysrc file.

The syntax should be pretty self-explanatory.

I can replace the "xvkbd..." line with any script to achieve other functions.

xvkbd documentation can be found at and xbindkeys's can be found at

Xilin Sun

Written by

Xilin Sun