Monday, March 10, 2014

Configuring extra mouse buttons in Linux

Most of mice's manufacturers don't support Linux to the extent that they would actually make a software where one could easily customize their mouse. There is no reason to despair though, the process is very, very simple.

We will need three packages - sudo apt-get install xbindkeys xautomation xev

Figuring out the button number

Now, we need to figure out which number corresponds with which mouse button. Run xev. A window will appear and by clicking a button on it the terminal will tell you to which number it is mapped:

ButtonPress event, serial 37, synthetic NO, window 0x3200001,
    root 0xb8, subw 0x0, time 18124629, (152,106), root:(1596,237),
    state 0x10, button 6, same_screen YES

ButtonRelease event, serial 37, synthetic NO, window 0x3200001,
    root 0xb8, subw 0x0, time 18124629, (152,106), root:(1596,237),
    state 0x10, button 6, same_screen YES

This means the clicked button is 6. We will need that later.

Setting up the script

Now is the time to look at xbindkeys. It is a program which translates certain buttons to other buttons. Sounds simple? That's because it is. Run xbindkeys --defaults > $HOME/.xbindkeysrc to create a config file. Then open the file and customize it. If we, for example, wanted to have button #6 translated to Alt+Left, we would add this entry:

"xte 'keydown Alt_L' 'key Left' 'keyup Alt_L'"
b:6

Restart xbindkeys by running killall xbindkeys followed by xbindkeys.

Care about not having spaces before b:6 - it didn't work for me when they were there.
And that is all. You can create others on your own, look up xev for more info about the syntax.

Tags: Logitech Linux mouse extra buttons custom setting