The information in this thread have been moved to https://help.ubuntu.com/community/MouseCustomizations
A thread for discussion of the wiki page only can be found here http://ubuntuforums.org/showthread.php?t=2012401
This is yet another mouse button customization guide. From reading these forums (and others on the net), I think the major unresolved issue for many users switching to Linux is the ability to set an arbitrary (usually the middle or thumb) button on a mouse to "double click" (typically double "left click"). I finally worked out a reasonable solution to this problem, and am including enough additional details that most people should be able to work out how to customize their mice. This is not to take away from a wide variety of other guides in these forums, but they are perhaps too specific (i.e., it's hard to modify the command set the poster presents, which typically don't work at all with my Marble Mouse trackball). These instructions rely only on X and distro-independent tools for it, so should work with most or all Linux distros with only minor changes. I have personally used or seen other people use parts of these instructions without problem in multiple versions/releases of Ubuntu and Debian.
NOTE: Please keep all help questions public (i.e., post here rather than private messaging me), as any question you have is most likely one that will benefit other users, and I do have a full-time job, so can't act as private support for anyone.
You may wish to try the program btnx: discussion at http://ubuntuforums.org/showthread.php?t=455656 and download at http://www.ollisalonen.com/btnx/. For many users, this program is probably easier and sufficient, and provides an interface similar to that for Logitech mice under Windows. However, btnx is still in development, so may not be entirely stable yet. Btnx also does not allow for some of the more complex combinations discussed below, such as modifier keys with mice buttons. Note: as of Sep 2008, btnx development has apparently ceased, due to something in Xorg 7.4 (released with Intrepid) permanently breaking the method btnx used to communicate with the mouse.
Updated 1 April 2008
SHORCUT: If all you want to do is set your four or five button mouse to use the extra buttons as "forward" and "back" buttons, you may have success with performing only a single action: edit /etc/X11/xorg.conf in the mouse section, and add the following two lines:
Make sure to backup the file first, and restart X to have the effect take place. Assuming you are one of the fortunate people who only wants these functions and whose mouse buttons map as the "standard" behavior, you'll be all set. If it does not work, or you want other functions, you'll need to follow the longer details below. (END SHORTCUT)Code:Option "Buttons" "7" Option "ButtonMapping" "1 2 3 6 7"
First, you need to install several programs. xbindkeys allows you to map any mouse (or keyboard) event to some program. xautomation is our gateway to setting up a "double click" event and mapping keyboard events to mouse buttons, and so it is not needed if you do not plan on using this.
NOTE: xvkbd seems to be the preferred tool in other threads instead of xautomation/xte, so if you wish you can use that instead of xautomation for all the same keyboard mapping tasks if you prefer that approach. xmacro is another tool that may work to replace xte for double click.
Open a terminal and type:
--Getting button numbers--Code:sudo apt-get install xautomation sudo apt-get install xbindkeys
Now we need to determine the "button number" of each physical button on your mouse.
This will open a window. Move your mouse cursor over it, and you'll see a lot of output in your terminal; don't worry about the output that happens when you move the mouse. One at a time, single click each button inside the "event tester" window, and note the 3rd line of output from either (or both) of the "ButtonPress" or "ButtonRelease" notices that pop up. The center item is "button X." Make a note of the number that matches each physical button on your mouse. Also note if one or more buttons do not respond.Code:xev
--Scroll Wheel and getting all buttons to respond--
First, get your scroll wheel working, if you have one. As I do not, this will be approximate, but the other guides available cover this in great depth if you need more help. Basically, the "scroll up" and "scroll down"are 2 more buttons on your mouse, so you will need to identify this as well using xev. Then type:
It is essentially to have a backup of xorg.conf, as messing it up can damage your ability to work to load your window environment. Search for "mouse." It should look something like this (although you may have additional lines):Code:sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup sudo gedit /etc/X11/xorg.conf
The only two lines we are going to touch are the "Protocol" and "ZAxisMapping" lines. Only change the Protocol line if one or more buttons did not respond. If you have unresponding buttons, chances are that you are using the PS/2 or IMPS/2 protocols, which may not allow for as many buttons (or the configuration) that you have, in which case try the ExplorerPS/2 as shown above. If you are already set to that and can't get buttons to respond (or get multiple button events in response to a single click), you probably need to use the "evdev" driver, described near the bottom of this post.Code:Section "InputDevice" Identifier "Configured Mouse" Driver "mouse" Option "CorePointer" Option "Device" "/dev/input/mice" Option "Protocol" "ExplorerPS/2" Option "ZAxisMapping" "6 7" Option "Emulate3Buttons" "true" EndSection
ZAxisMapping refers to the scroll wheel. Basically, the simplest way to get the scroll wheel to work is to change the "6 7" above to match the two scroll button numbers from xev.
You will need to restart X (logout & press Ctrl + Alt + Backspace) to have these changes go into effect. If you changed the protocol, you will need to resume at the beginning (getting button numbers) as they will probably have changed. If your scroll wheel still does not work, try this in the terminal (the pointer should have as many numbers as from the -pp output, each only once):
This first outputs your current mapping of buttons. Basically, this means that the number shown (in the pointer) is the button # that triggers the events normally associated with the button position (i.e., here X & Y should be replaced with your 2 scroll buttons, to get them to trigger the 6 & 7 events). Note that if you use xmodmap, you will to auto-load this each time you start X (in Gnome, go to System -> Preferences -> Sessions -> StartUp, and add the xmodmap command. Also note that xmodmap takes effect immediately; you do not need to restart.Code:xmodmap -pp xmodmap -e "pointer = 1 2 3 4 5 X Y 6 7 ..."
You may also need to add a "buttons" option and try remapping in xorg.conf; see the other tutorials and http://www.die.net/doc/linux/man/man...-driver.4.html for more details.
As mentioned above, you can use xmodmap to rearrange buttons. This is useful if, as with my marble mouse, none of the buttons are set to be the "middle" button, which can be a problem in some programs. The middle button is button position 2. On my mouse, I have 4 buttons, which are assigned numbers 1, 3, 8, and 9. I use this:
to assign button 8 to be the "middle button" (and assign position 8 to button 2, which does not exist). Note that I am also using this left-handed, so my right- & left-click buttons are swapped ("normally" the 1 is left-click and 3 is right-click). In my case, positions which are assigned numbers 2 & 4-7 do not have any function, since I do not have any of those button numbers. Again, you must run xmodmap each time you login for this to work.Code:xmodmap -e "pointer = 3 8 1 4 5 6 7 2 9"
--Setting up double click--
I know it's taken a while to get here, but the unique point to this howto: setting an arbitrary button to be a "double click." To follow what we're going to do, understand that there is no such thing as a "double click" event. What we are actually going to do is assign a button to give 2 "left-click" events.
Installing xautomation provided us with several tools (use "man xautomation" if you're curious), but the key one is "xte." This allows us to send arbitray mouse (& keyboard) events to the kernel. We will also make use of xbindkeys to first trap the button event. First, create .xbindkeysrc, which xbindkeys uses for trapping events:
Now type:Code:gedit ~/.xbindkeysrc
orCode:"/usr/bin/xte 'mouseup Y' 'mouseclick 1' 'mouseclick 1' &" b:Y
(The difference is whether you want the double click to to respond when you first click the mouse, or only when you release the button, respectively.)Code:"/usr/bin/xte 'mouseclick 1' 'mouseclick 1' &" b:Y + Release
Replace "Y" in "b:Y" with the button number of the button you wish to assign to double-click. Save & close this file.
This starts xbindkeys running in the foreground, which means it will tell you if there are problems with your file. If you click the button Y, you should see xbindkeys provide trapping feedback upon release, and see feedback as well from button 1. Press "Ctrl + C" to stop this interface, then (if everything is working):Code:xbindkeys -n -v
which will load xbindkeys in the background, and you should be set. As with xmodmap (end of the Scroll Wheel section), you need to add xbindkeys to start when X loads for this to work long-term.Code:xbindkeys &
Basically, adding any other function to your mouse is going to use xbindkeys via the .xbindkeysrc file, except the command line will look something like this:
This example binds "Alt + Left Arrow" to button Z, which works as "back" in Firefox (and a variety of other applications). You can read many more examples of key combinations here using "man xte" or at the xbindkeys site: http://hocwp.free.fr/xbindkeys/xbindkeys.html . The examples there mostly show to how invoke programs, but you can still get the example keys and just substitute in the example above. Also at the site are scripts (and at least one example of how to use in their config files, I think for invoking emacs two different ways) on mapping multiple events to a single button (e.g., if single click button Z, go back; if double-click, go forward).Code:"/usr/bin/xte 'keydown Alt_L' 'key Left' 'keyup Alt_L' &" b:Z
For those wishing to set "scroll up" & "scroll down" buttons that repeat (i.e., advance multiple times instead of just once per click), it should be possible to set up a short script that loops the xte event & a short sleep event as long as the button is held down, and invoke that script in .xbindkeysrc, but I have not actually tested this.
EDIT: see the next few posts for how to get scroll working for multiple advances.
Also note that xbindkeys is a great way to get keyboard combinations working (e.g., that useless Windows key, the multimedia keys you may have, or other random combinations to load favorite programs).
--Application specific settings--
See this thread: http://www.ubuntuforums.org/showthread.php?t=380927.
Or post #30 below for an equivalent approach.
--Dealing with different settings for laptops when external mouse connected--
See this thread for a start: http://www.ubuntuforums.org/showthread.php?t=350464.
If you have multiple scroll wheels or buttons that are not recognized, you probably need to use the evdev driver. This is a little more complicated to set up. Much of this section is stolen from another mouse guide: https://help.ubuntu.com/community/MX1000Mouse.
Note to Hardy users: the evdev driver was changed significantly for Xorg 7.3, released with Hardy. The below will not work. You may be able to replace Option "Name" with Option "by-path" and choose the correct device from /dev/input/by-path/, but users are reporting mixed success with this on Launchpad. Some of the other configuration options for evdev have also apparently been dropped.
If running pre-Gutsy releases, install evdev (it is install by default in Gutsy):
Then you need to identify the name of your mouse (or its receiver, if wireless):Code:sudo apt-get install xserver-xorg-input-evdev
Which will yield output something like this (on my computer):Code:cat /proc/bus/input/devices
You are looking for the one that implies a mouse, or the manufacturer of your mouse (not the Macintosh mouse buttom emulation) and generally would refer to "mouse" in the "Handler" line of the section; in my cases, this is the 5th entry with the name "Logitech USB Trackball". Make a note of the name line, including all capitalization exactly.I: Bus=0017 Vendor=0001 Product=0001 Version=0100
N: Name="Macintosh mouse button emulation"
H: Handlers=mouse0 event0
B: KEY=70000 0 0 0 0 0 0 0 0
I: Bus=0010 Vendor=001f Product=0001 Version=0100
N: Name="PC Speaker"
H: Handlers=kbd event4
I: Bus=0003 Vendor=05a4 Product=9998 Version=0100
N: Name="NOVATEK USB Keyboard"
H: Handlers=kbd event1
B: KEY=10000 7 ff87207a c14057ff febeffdf ffefffff ffffffff fffffffe
I: Bus=0003 Vendor=05a4 Product=9998 Version=0100
N: Name="NOVATEK USB Keyboard"
H: Handlers=kbd event2
B: KEY=c000 100000 0 0 0
I: Bus=0003 Vendor=046d Product=c408 Version=0110
N: Name="Logitech USB Trackball"
H: Handlers=mouse1 event3
B: KEY=1f0000 0 0 0 0 0 0 0 0
I: Bus=0019 Vendor=0000 Product=0002 Version=0000
N: Name="Power Button (FF)"
H: Handlers=kbd event5
B: KEY=100000 0 0 0
I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button (CM)"
H: Handlers=kbd event6
B: KEY=100000 0 0 0
Edit (after backing up!) your xorg.conf as described above, replacing the existing mouse section section (between the "Section..." and "EndSection" lines) with this:
replacing the Identifier to reflect what you wish to call your mouse, and the Option "Name" with the name of your mouse from the output desribed above.Code:Identifier "Logitech Trackball" Driver "evdev" Option "Name" "Logitech USB Trackball"
Then replace the
near the bottom of xorg.conf with this (replacing your name as needed):Code:InputDevice "configured mouse"
NOTE: If you using a laptop where your mouse will not always be connected, use "SendCoreEvents" instead of "CorePointer".Code:InputDevice "Logitech Trackball" "CorePointer"
Save & close xorg.conf and restart X, then resume the guide above (note that the ZAxisMapping trick won't work with evdev).
Also note with the evdev driver that some buttons will report two events (e.g., the "tilt wheel" of Logitech mice). The first button, usually the higher number, is the "start/stop" signal for the event, while the second button, usually lower and repeating, is the button you usually want to modify to change a function. I've not found a way on those mice to change which button is triggered (e.g., the "cruise" buttons on the Logitech MX1000 trigger buttons 4 & 5, which are the same as the scroll wheel, so you can't change the cruise effect separately from an effect on the scroll wheel).
So sorry for the marathon length, but hopefully this explains more of how things actually work, and will allow people to customize their mice in a fairly straightforward fashion. I will attempt to key an eye on this if anyone wants to provide feedback, point out problems, or needs additional help, but I'm trying to finish up my PhD so I can move on with my life, so I won't have a lot of time (I've already spent far too much on this problem). Feel free to re-post, abbreviate, correct, etc. Finally, for those long-time Linux users who may respond "just use KDE" or other useless pieces of "advice" to avoid the need for a double-click altogther, I just want to say that there are plenty of good reasons to want a separate single & double click event for normal users, and especially for those who have trouble physically double-clicking (most Linux users seem to forget out the "accessibility" issue of computers, though I find these forums to be much better than forums elsewhere - Ubuntu users must just be nicer people. 8) )