Bind Mouse Buttons to Keys or Scripts under Linux with xbindkeys and xvkbd
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
xvkbd. This should work for most mice and trackballs under
X (probably not under
yaourt -Sy xbindkeys xvkbd
Get button codes
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:
ButtonPress event, serial 38, synthetic NO, window 0x4000001, root 0x398, subw 0x0, time 22026698, (73,117), root:(74,182), state 0x4, button 1, same_screen YESButtonRelease event, serial 38, synthetic NO, window 0x4000001, root 0x398, subw 0x0, time 22026818, (73,117), root:(74,182), state 0x104, button 1, same_screen YES
The left button is recognized as
Using the same method, I have got the codes for all the (usable) buttons on my MX Ergo:
1: left button 2: mid button (scroll wheel clicked down) 3: right button 4: scroll up 5: scroll down 6: scroll wheel tilt left 7: scroll wheel tilt right 8: back button 9: forward button
I marked all these buttons in the picture below. The switching device button and precision button are not avilable for the operating system.
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
# Button 6 closes a tab "xvkbd -text '\Cw'" # Sends Ctrl-w b:6# Button 7 opens a tab "xvkbd -text '\Ct'" # Sends Ctrl-t b:7# Button 8 sends Control + PageDown "xvkbd -text '\C\[Next]'" # Sends Ctrl-PgDn b:8# Button 9 sends Control + PageUp "xvkbd -text '\C\[Prior]'" # Sends Ctrl-PgUp b:9
The syntax should be pretty self-explanatory.
I can replace the
"xvkbd..." line with any script to achieve other functions.