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
Code:
sudo apt-get install 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:
Code:
"echo 'KeyStrPress Enter KeyStrRelease Enter' | xmacroplay :0"
b:1
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:
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:
Code:
# 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.
Code:
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:
You should see things like this:
Code:
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:
Code:
# 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:
Code:
# Mapping enter key to mousewheel right
"echo 'KeyStrPress Return KeyStrRelease Return' | xmacroplay :0"
b:7
# Mappings for media wheel
"echo 'KeyStrPress XF86AudioNext KeyStrRelease XF86AudioNext' | xmacroplay :0"
b:13
"echo 'KeyStrPress XF86AudioPrev KeyStrRelease XF86AudioPrev' | xmacroplay :0"
b:15
"echo 'KeyStrPress XF86AudioPlay KeyStrRelease XF86AudioPlay' | xmacroplay :0"
b:17
5) Test your configuration
Once all of the above is setup, test your configuration by running:
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!