Getting Logitech custom mouse buttons working within Linux

Saturday, 23rd April 2011

Having lived in a Windows environment for the past couple of years I've gotten somewhat used to my routines and short cuts, most of which are missing or changed now that I'm 95% Ubuntu. The most notable absentee are all the extra buttons on my Logitech MX Revolution mouse, which I have mapped to a vast array or custom key stroked. So, lest I forget, this is how I have got these custom buttons working correctly.

Introduction
All these buttons are detected by the latest kernel (which as of writing is)
  stuart@TaiChi:~$ uname -a
  Linux TaiChi 2.6.35-28-generic #50-Ubuntu SMP Fri Mar 18 18:42:20 UTC 2011 x86_64 GNU/Linux
This is grate news because all we need to do now is map each button against the desired application/keystroke. My system of choice is Ubuntu 10.10 so all the command line and install command listed are correct for this distributions as of writing. If you find other commands work on other distributions leave a not in the command and I will be sure to update the main article.
  1. 1We should install xbindkeys. This will re-map mouse and keyboard inputs so the install is...
    $ sudo apt-get install xbindkeys
    The goal is to configure the mouse buttons to send key combinations to activate other desktop or application functionalities. Technically all xbindkeys is doing is executing an application in response to a keystroke or mouse button.
  2. 2So in-order to map a mouse button to a keystroke we have to install an application called xte which simulates user key press combinations. In Ubuntu 10.10 this comes as part of the xautomation package which can be installed like this
    $ sudo apt-get install xautomation
  3. 3Now we need to create a configuration file for xbindkey, which can be done like this...
    $ xbindkeys --defaults > $HOME/.xbindkeysrc
  4. 4We need to edit this file in a text editor. I use kate, being the default for KDE, however you can of course use what ever editor you would prefer to...
    $ kate ~/.xbindkeysrc
    The xbindkeys configuration file has a very simple format...
    "command_to_run"
      keyboard_or_mouse buttons
  5. 5So we need to add our button-to-key configurations, but first we need to know what 'events' the mouse buttons are triggering before we can remap them. For this we can use xev this program is a key and mouse event sniffer. It runs by opening a small window. You can now start pressing keyboard or mouse buttons over the window and see if they are detected. For example the forward button on my Logitech Revolution MX looks something like this:
    ButtonRelease event, serial 30, synthetic NO, window 0x6400001,
        root 0x15a, subw 0x6400002, time 31049598, (33,57), root:(979,126),
        state 0x10, button 8, same_screen YES
  6. 6Now that we have a list of all our button codes we can more on to actually writing the configuration file. For example I have this to map my back and forward buttons to Firefox back/forward key combinations. For example I have this to map my back and forward buttons to Firefox back/forward key combinations.
    # Back
    "xte 'keydown Control_L' 'key bracketleft' 'keyup Control_L'"
      b:8
    
    # Forward
    "xte 'keydown Control_L' 'key bracketright' 'keyup Control_L'"
      b:9
  7. 7It really is this easy, all you have to remember thought is after editing your ~/.xbindkeysrc you need to refresh the daemon by executing /usr/bin/xbindkeys. Other wise your mouse will not recognize the changes.
  8. 8Last Step. You now need to get the xbindkey daemon to automatically run at system startup. In KDE just go to 'System Settings / Startup and Shutdown / Autostart / Add program button' and type /usr/bin/xbindkeys in the dialog

Save & Share This...


Comments
Avatar
root
  • 08:57

I am still having some issues mapping the XF86Search button to an alternative command, I like it as a Cache-less refresh in Firefox.

But I just wanted to say I will post an update as soon as I have it working. I'm also working on some quick graphical mappings from my hardware, anyway, more about that soon.

In the mean time keep an eye on my Twitter feed or subscribe to our RSS feeds for updates for further updates.

As always, if you have been, thanks for reading.

Add new comment

Sanitized HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.