Logitech MX Revolution

From ArchWiki
Revision as of 02:49, 29 April 2009 by Ilikepudding (talk | contribs)
Jump to: navigation, search

Originally Posted by NobodySpecial on the forums April 12, 2007:

Many of us were using BTNX to run the buttons on the MX Revolution. But BTNX is now broken with the new XORG. The good news is, the new XORG is good enough that you don't really need BTNX, for the most part.

Here's how I use mine. First, I'm not even using the evdev driver - I guess you could. But "mouse" works fine: /etc/X11/xorg.conf

   Section "InputDevice"
   Identifier    "MX Rev"
   Driver        "mouse"
   Option        "CorePointer"
   Option        "Device"        "/dev/input/mice"
   Option        "Protocol"        "auto"
   Option        "ZAxisMapping"        "4 5"
   Option        "Emulate3Buttons"    "no"
   Option        "Buttons"        "3"

To start, install a couple packages:

   sudo pacman -S xbindkeys xvkbd

Then find the buttons you want with xev and enter in ~/.xbindkeysrc My code under ~/.xbindkeysrc makes the thumb buttons go forward/back and also the middle mouse wheel rock left/right will change tabs in firefox:

   "/usr/bin/xvkbd -xsendevent -text "\[Alt_L]\[Left]""
     m:0x0 + b:8
   "/usr/bin/xvkbd -xsendevent -text "\[Alt_L]\[Right]""
     m:0x0 + b:9
   "/usr/bin/xvkbd -xsendevent -text "\[Control_L]\[Page_Up]""
     m:0x0 + b:6
   "/usr/bin/xvkbd -xsendevent -text "\[Control_L]\[Page_Down]""
     m:0x0 + b:7

To automate, add /usr/bin/xbindkeys to System -> Pref -> Sessions. Next, I like the left-sided wheel to rotate the desktop in compiz: Compiz Settings -> Desktop -> Rotate Cube -> Bindings -> Initate "Button17", Rotate Left "Button13", Rotate Right "Button15" Finally, its annoying to me that the middle button below the scroll wheel is set to "search". Its far handier to have it as the middle mouse click. The only way I found to do this is through Xmodmap, which isn't ideal, but works (PLEASE post here if you know a better way). To list xmodmap keys: xmodmap -pk OR xmodmap -pke Under xev above, my button gives "keycode 225", so I do this:

   echo "keycode 225 = Pointer_Button2" >> ~/.xmodmaprc

Log out and in again - gnome should autodetect the ~/.xmodmaprc file. The trick only works when "mousekeys" are on. So either gnome-keyboard-properties -> Mousekeys -> Enable pointer OR toggle with SHIFT-ALT-NUMLOCK (you want to be able to toggle so you can use the numeric keypad at times). However, the xmodmap trick has one more issue - it messes up keybindings in vmware. This solved it for me:

   echo "xkeymap.nokeycodeMap = true" >> /etc/vmware/config

Originally Posted by WCentauri on the forums August 14, 2008:

I suggest a slightly different way to handle the mapping of the search button to middle click. The output from xev lists the button as XF86Search, and it can also be referenced as c:0xE1. It should be possible to map the search button with xbindkeys by referring to c:0xE1 or XF86Search and using the xmacro package available in the AUR. The corresponding entry for xbindkeys is

   "echo 'ButtonPress 2 ButtonRelease 2' | xmacroplay :0"

I'm not sure that xvkbd can remap mouse buttons. Perhaps this is why xmodmap was used in the first place. xmacro can handle keyboard and mouse buttons, so the other entries in .xbindkeysrc could be transformed to xmacroplay calls. I don't have a compelling reason (besides aesthetics) for doing so, other than anecdotal claims that xmacro has less overhead than xmacro. This may or may not be true, and it may not matter for practical purposes anyway.

There is a big thread ([1]) brewing on the Ubuntu forums about the death of btnx, and that is where this technique comes from.

Post from the above link to the Ubuntu Forums:

With the release of Ubuntu 8.10, BTNX has been broken. As such, I figured I'd write up a small, hopefully as clear as possible tutorial on how to 'replace' it with a few other simple utilities.

There have been a few others posts on this, and I've found them helpful after some head scratching. I figured I'd try to make a simple, unified post.

So here is how I got my Logitech MX Revolution working again.

1) Install 2 utilities: xmacroplay and xbindkeys

   sudo apt-get install xbindkeys xmacro

Note: For arch, this would be

   pacman -S xbindkeys xmacro

xbindkeys runs commands when certain keyboard key presses or mouse button presses are detected. xmacro is a program for playing, shocker, macros. It can be used to generate, amongst other things, keypresses in an X window

2) Go through the (painful) button discovery process. To do this:

a) edit the configuration file for xbindkeys

gedit ~/.xbindkeysrc

delete the full contents of this file and add the following lines:

   "echo 'KeyStrPress Enter KeyStrRelease Enter' | xmacroplay :0"

This will echo a very simple macro to the macro player which will direct the results of said macro to the default X display. In this case, it will generate a press of the 'enter' key.

b) launch a text editor window. We will use this to see the results of the macro running

c) run the following command in the terminal window:

   xbindkeys -n -v

Note: This will likely prevent the normal functioning of whatever button you are looking for.

d) select the text editor and start pressing mouse buttons until you get an 'enter' that will be button b:1 for your mouse. Once you find the button, reselect the terminal and Ctrl+C the process to stop it.

Repeat the whole process for different b:#'s (i.e. b:2). Make sure to note what button codes correspond to which buttons. Also, try multi button presses if no single button generates an event. For instance on my Revo, pressing the left and right buttons together is b:3

You should be able to find the button codes for most buttons using this process. On my mouse, the only button I couldn't find was the search button (which is handled differently by the OS for some odd reason).

For my mouse, the list looked like this:

   # Mappings for keys for MX Revo
   # b:1	-	left mouse button
   # b:2	-	left and right mouse button together
   # b:3 	-	right mouse button
   # b:4	-	mouse wheel up
   # b:5	-	mouse wheel down
   # b:6	-	mouse wheel left
   # b:7	-	mouse wheel right
   # b:8	-	back button
   # b:9	-	forward button
   # b:10	-	-none-
   # b:11	-	-none-
   # b:12	-	-none-
   # b:13	-	media wheel up
   # b:14	-	-none-
   # b:15	-	media wheel down
   # b:16	-	-none-
   # b:17	-	media wheel press

this list is only for your refrence when you start binding button presses to macros. You don't need to have it anywhere in any file (but it dosen't hurt to note them as comments in the ~/.xbindkeysrc file.

3) Figure out the Xmacro names for the keys you want to simulate

xmacro uses special codes to represent key presses and button clicks. The simplest way to figure out what codes to use for what you want to do is by using the xmacrorec2 utility.

To do this, start xmacrorec2 in a terminal and redirect the output to a reference file.

   xmacrorec2 > dump.txt

After starting xmacrorec2, press the scroll lock key to start recording actions. Then press any key or button you'd like to know the code of. When done, press scroll lock again to stop recording. Then look in the dump.txt file:

   cat dump.txt

You should see things like this:

   MotionNotify 378 241
   KeyStrPress XF86AudioMute
   KeyStrRelease XF86AudioMute
   KeyStrPress XF86AudioMute
   KeyStrPress XF86AudioLowerVolume
   KeyStrRelease XF86AudioMute
   KeyStrRelease XF86AudioLowerVolume
   KeyStrPress XF86AudioLowerVolume
   KeyStrRelease XF86AudioLowerVolume
   KeyStrPress XF86AudioLowerVolume
   KeyStrPress XF86AudioRaiseVolume
   KeyStrRelease XF86AudioLowerVolume
   KeyStrRelease XF86AudioRaiseVolume

4) Create your configuration file

Using the button codes from step 2 and the xmacro codes from step three, form your configuration file. Use the following format:

   # Example for a key press
   "echo 'KeyStrPress <xmacro code> KeyStrRelease <xmacro code>' | xmacroplay :0"
   <mouse button code>

where <xmacro code> is replaced (including carrots) with the keyboard code from step three and where <mouse button code> is replaced with a button code from step two.

Simulating mouse button presses is a bit different, but follows the same idea.

The above example will simulate a key press followed by an immediate key release. To configure multi-key presses, simply list all the keys, first as presses, then as releases, in a list seperated by spaces.

My final simple configuration file ended up looking like this:

   # Mapping enter key to mousewheel right
   "echo 'KeyStrPress Return KeyStrRelease Return' | xmacroplay :0"
   # Mappings for media wheel
   "echo 'KeyStrPress XF86AudioNext KeyStrRelease XF86AudioNext' | xmacroplay :0"
   "echo 'KeyStrPress XF86AudioPrev KeyStrRelease XF86AudioPrev' | xmacroplay :0"
   "echo 'KeyStrPress XF86AudioPlay KeyStrRelease XF86AudioPlay' | xmacroplay :0"

5) Test your configuration

Once all of the above is setup, test your configuration by running:

   xbindkeys -n -v

in a terminal window. Leave the terminal up and let the code run and try out your mappings. When you are satisfied everything is working correctly, close the terminal window, and add a strait call to xbindkeys with no flags to your session. For gnome, this involves opening the System->Prefrences->Sessions, click on Add, then put any name (i.e: xbindkeys) and put xbindkeys in the command box (without the -n (not daemon) and -v (verbose) options), just xbindkeys. The next time you restart you system xbindkeys will run automatically.

Please let me know if anything here is unclear. Also, feel free to post your button mappings for others to use!