Difference between revisions of "Mouse buttons"

From ArchWiki
Jump to navigation Jump to search
(Installing the evdev Drivers: Changed reference to current repo)
Line 17: Line 17:
=== Installing the evdev Drivers ===
=== Installing the evdev Drivers ===
The first thing you need to do is install Xorg evdev package. The package cab be found in Current and is
The first thing you need to do is install Xorg evdev package. The package can be found in <code>[Extra]</code> and is
named [http://www.archlinux.org/packages/10240 xf86-input-evdev].  
named [http://www.archlinux.org/packages/10240 xf86-input-evdev].  

Revision as of 18:21, 28 December 2007

About / Prerequisites

This article is for users that have a mouse with more than 7 mouse buttons and want to be able to use all of them. Logitech makes several of these, and Microsoft makes a few as well. If you have one of these mice, read on!

  • NOTE: These are helper comments, and can be ignored if you are looking for nothing but raw information. Due to community feedback, I decided to add a bit more commenting that describes what's going on "behind the scenes" with this configuration.

We will be using the evdev driver for Xorg. EVentDEVice is an advanced driver for USB input devices which offers much greater power over the standard Xorg mouse driver. It's also more "direct" than the mouse driver, allowing lower latency and less translation issues.

  • Note that evdev is both a kernel module and an Xorg input driver. All the Arch kernels come with the evdev module.

With the newer xorg 11R7.0 it seems only the following changes to /etc/X11/xorg.conf need to be made with nothing else needing to be done.

Installing the evdev Drivers

The first thing you need to do is install Xorg evdev package. The package can be found in [Extra] and is named xf86-input-evdev.

pacman -S xf86-input-evdev

After it has been installed, modprobe the evdev module.

modprobe evdev

Now check the output of dmesg and make sure that evdev didn't have any errors. If everything worked, move on to the next section.

Finding the Mouse Name

Note: To get accurate information it is sometimes required to execute this command from a boot where no Xorg or mouse drivers have been loaded.

The first step is to find the name of the mouse. To do this, execute the following command:

egrep "Name|Handlers" /proc/bus/input/devices

This should output something like this:

N: Name="Logitech USB Gaming Mouse"
H: Handlers=mouse0 event0 ts0 
N: Name="HID 0566:3002"
H: Handlers=kbd event1 

The mouse is the one that has the Handlers=mouse0, so the name of the device is Logitech USB Gaming Mouse.

  • My mouse is a Logitch G5, your mouse is probably different, and therefore the Name will be different.

Copy the name of the device, and open up /etc/X11/xorg.conf.

Configuring Xorg

Now, we need an entry in xorg.conf that tells X how to use this mouse. It should look something like this:

Section "InputDevice"
  Identifier      "Evdev Mouse"
  Driver          "evdev"
  Option          "Name" "Logitech USB Gaming Mouse"
  Option          "CorePointer"

Replace the "Name" option with the name you copied from above. You may also omit the "CorePointer" option if you use multiple mice or experience errors when attempting to load Xorg.

Next, we need to tell X to use the mouse, so look in xorg.conf for ServerLayout.

Modify the InputDevice section to use "Evdev Mouse" as the device. When you are done, it should look something like this:

Section "ServerLayout"
  Identifier     "Default Layout"
  Screen 0       "Monitor0" 0 0
  InputDevice    "Keyboard0" "CoreKeyboard"
  InputDevice    "Evdev Mouse" "CorePointer"

The only thing you should change in the layout is the InputDevice line that refers to your mouse.

That should be all that's required.

Post Configuration


It just works™.


By default, left right scroll on Fx translate into back/forward, respectively. If you don't like this, open about:config and change a few values:

mousewheel.horizscroll.withnokey.action      0
mousewheel.horizscroll.withnokey.numlines   -3

If you use a positive value for numlines, your left/right will switch, ie: pressing left scrolls the window to the right.


To get the back and forwards buttons working in this browser open about:config and change these values:

mousewheel.horizscrool.withnokey.action         2
mousewheel.horizscrool.withnokey.sysnumlines    false


For the back and forward button to work, imwheel is needed.

 pacman -Sy imwheel

Create the file .imwheelrc in your home dir:

 None, Up, Alt_L|Left
 None, Down, Alt_L|Right

Make sure imwheel is started during kde start. Create a file ~/.kde/Autostart/imwheel With the following contents:

 xmodmap -e "pointer = 1 2 3 4 5 8 9 6 7 10 11"
 killall /usr/bin/imwheel
 imwheel -k -b "67"

You can find you buttons by execute imwheel -D in a console and see which buttons belong to the back and forward button.

xmodmap tweaking

NOTE: None of the below is necessary with evdev, but it's here for non-evdev users. Unless something doesn't work on your mouse, ignore this whole section!

If you use .xinitrc to load X, then add this to .xinitrc (change for the number of buttons you have):

 xmodmap -e "pointer = 1 2 3 6 7 8 9 10 11 12 4 5" &

Note that buttons 4 and 5 must go on the end or else your scroll wheel won't work.

If you use GDM/XDM/KDM instead of .xinitrc, then create the file ~/.Xmodmap and add this to it (change for the number of buttons you have):

 pointer = 1 2 3 6 7 8 9 10 11 12 4 5
  • GDM/XDM/KDM read the ~/.Xmodmap file if it's present, whereas startx does not. Another solution would be to add this to your ~/.xinitrc: xmodmap -e $(cat ~/.Xmodmap). This would allow you to use *DM and startx while only having to edit ~/.Xmodmap when you need to make changes.

You may have to play with these numbers a bit to get your desired behavior. Some mice use buttons 6 and 7 for the scroll wheel, in which case those buttons would have to be the last numbers. Keep playing with it until it works!

You can also check to see which buttons are being read with a program called 'xev', which is part of XOrg. When xev is run, it will show a box on your desktop that you can put the cursor into and click buttons to find out what buttons have been mapped.

Alternate Methods

The following methods use standard X.org mouse input driver (xf86-input-mouse) instead of using the evdev driver. It works on mice up to 7 buttons. Edit /etc/X11/xorg.conf InputDevice section for your mouse to reflect the changes shown below. Then restart X and you're done.

Method 1 - IMPS/2

This has been tested on an IntelliMouse Explorer 3.0. Your mileage may vary, as this does not seem to work for all said mice.

   Driver      "mouse"
   Option      "Protocol" "IMPS/2"
   Option      "Device" "/dev/input/mice"
   Option      "ZAxisMapping" "4 5 6 7"

Method 2 - ExplorerPS/2

This has been tested on a Logitech MX400 and MX518 and should work on any mx series mouse with up to 7 buttons.

   Driver         "mouse"
   Option         "Protocol" "ExplorerPS/2"
   Option         "Device" "/dev/input/mice"
   Option         "Buttons" "7"
   Option         "ZAxisMapping" "4 5"
   Option         "ButtonMapping" "1 2 3 6 7"

Method 3 - Auto

This has been tested on a Logitech MX400 and should work on most mice with up to 7 buttons.

   Driver         "mouse"
   Option         "Protocol" "auto"
   Option         "Device" "/dev/input/mice"
   Option         "Buttons" "7"
   Option         "ZAxisMapping" "4 5"
   Option         "ButtonMapping" "1 2 3 6 7"

Method 4 - btnx

btnx: Button Extension- a GNU/GPL mouse tool for GNU/Linux

This allows the use of all buttons on the Logitech MX Revolution and reportedly other multi-button mice as well. Provides greater control & configuration than the evdev driver.

Install via AUR: btnx-config then btnx Be sure the xorg.conf "Device" is at the default "/dev/input/mice" rather than "evdev".

Binding keyboard to mouse buttons

xvkbd and xbindkeys

Let's say we want to bind some mouse buttons to keyboard ones. The problem we will encounter is that we don't know how to emulate a key press. Here comes in handy xvkbd. It isn't available via pacman, but we can find it on AUR [1]. We can use it along with xvbindkeys.

pacman -S xbindkeys
xbindkeys --defaults >> ~/.xbindkeysrc

to restart xbindkeys type:

pkill -f xbindkeys

Here's example ~/.xbindkeysrc config:

"xvkbd  -text "\[F8]""
       m:0x0 + b:8
"xvkbd  -text "\[Shift]\[Left]""
       m:0x0 + b:9
"xvkbd  -text "\[Shift]\[Right]""
       m:0x0 + b:10
"xvkbd  -text 2"
       m:0x0 + b:11
"xvkbd  -text 3"
       m:0x0 + b:12

if you want to check your mouse buttons number use xev. Don't forget to type capital letters in xvkbd -text usage and to escape opening bracket with \, or you get simply [Shift] written.

Why standard methods are not enough?

This will work great for X servers, but it seems not to work in some specific situations, like in Enemy Territory game. So I will describe a bit more advanced configuration, which work with my logitech G5 buttons - I can use all my 5 additional buttons along with 3 standard and a scroll, which gives overall 10 events to use in Enemy Territory. So here we go:


To emulate keystroke which will be later detected in Enemy Territory we need something more advanced than xvkbd. Here comes in handy kbde, but it doesn't exist in AUR yet - we've got to compile it by ourselves. We need two programs: kbde and kbde-driver. Kbde website is located on sourceforge [2], check it for download, you need only kbde-driver. Apparently, it doesn't work for me without some hacking. Use your editor and add

#include <linux/version.h>

somewhere near other includes in the driver/kbde.c file. (OK, I'm not sure whether it is a proper way to compile it, but it works). Assuming that you've already done that try:

tar -zxvf kbde-driver-1*
cd kbde-driver-1*
# if you don't have sudo just use su and type this as root
sudo make install mknod
modprobe kbde

and now you should have kbde working. If you want to use it as a non-root (yes, you want) change permissions, the quickest and dirtiest way is (note that I added my startup scripts at the end of this text):

chgrp users /dev/kbde
chmod 220 /dev/kbde

If not try reading installation instructions on the site. Now we can use it to emulate keystrokes visible even in login shells:

kbde --press 5 --release 5 -b

this will press 5 for about three times. If you want to type a string using this, rather than this use --asci=STRING, as press sometimes generates 3 strokes before it is released.


Now we need something which will work when Enemy Territory is loaded. Apparently, xbindkeys doesn't work here, so we need another program, which isn't added to AUR: evrouter [3]

wget http://freshmeat.net/redir/evrouter/47427/url_tgz/evrouter_0.3.2.tar.gz
tar -zxvf evrouter_0.3.2.tar.gz
cd evrouter
./configure --prefix=/usr/
make install
# if you want to know more at this point use:
man evrouter

OK, so now we must have evdev and we canNOT use it in X, so here's how my example /etc/X11/xorg.conf mouse section looks like:

 Section "InputDevice"
   Identifier  "Logitech G5"
   Driver      "mouse"
   Option      "Protocol" "Auto"
   Option      "Device" "/dev/input/mouse1" # probably you'll need here mouse0
   Option      "Name"   "Logitech USB Gaming Mouse"
   Option      "Buttons" "8" # set this to your number of buttons
   Option      "ZAxisMapping" "4 5"


and now we've got to restart X server. You will run this as user, and event devices are owned by root, so you got to change the permissions at this point. Let's say we do it just like that, but I advice you to do this more carefully (note that I added my startup scripts at the end of this text):

chgrp users /dev/input/event*
chmod 660 /dev/input/event*

Now we can use --dump option to check what we will have to bind and to which device:

evrouter --dump /dev/input/event*
# here click buttons you would like to bind

It will give you output similar to config. Here's my example config ~/.evrouterrc with kbde usage:

"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/278 "SHELL/kbde --press 2 --release 2 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/279 "SHELL/kbde --press 3 --release 3 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/274 "SHELL/kbde --press 4 --release 4 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/277 "SHELL/kbde --press 5 --release 5 -b"
"Logitech USB Gaming Mouse" "/dev/input/event.*" any key/276 "SHELL/kbde --press 6 --release 6 -b"

this works great, even in enemy territory. "none" modifier means that I have to only press the button, other options are ctrl+alt and so on. Here I use "any" because "none" means that after pressing shift, ctrl or alt our buttons would not work. Also note that it accepts regex for mouse name and event path. Then, after setting up a config, run service with:

evrouter /dev/input/event* >> /dev/null

or change the event* to a device corresponding to your mouse - but be aware that the numbers are changing sometimes. It will work in background, while outputting some annoying messages, so we stream it to devnull. If something went wrong, run it without streaming and check what it outputs. If you want to end it, you have to delete /tmp/evrouter.* manually, here's a script to kill evrouter:

evrouter -q
rm -f /tmp/.evrouter*

and here's one to start it:

mydevicename="Logitech USB Gaming Mouse"

device=`evrouter -D /dev/input/event* | grep "$mydevicename"` | cut -d ":" -f 2
evrouter $device > /dev/null

You have to edit the mydevicename var to proper value (the one which is shown by evrouter -D), or just change it to listen on all events by changing device var to /dev/input/event*. OK, I've saved them in /usr/bin/ . Now, everything should be ready for use!

binding + and - in logitech G5 mouse

If you want to bind buttons + and - in G5/7 mouse, which normally changes dpi, you have to use g5hack [4] released by a lomoco author.

wget http://piie.net/temp/g5_hiddev.c
gcc -o g5hack g5_hiddev
./g5hack /dev/usb/hiddev0 3

This will change your dpi to 2000, light the 1st led and disables dpi on-the-fly changing, so you can use it with evrouter. If you would use it frequently I suggest you to copy it to the /usr/bin dir:

sudo cp g5hack /usr/bin/

startup scripts

Currently, I am using startup script with a bit dirty methods, so if somebody can propose better, please edit. I have created input group and make my user a member of it. /etc/rc.local:

# creating /dev/kbde nod and changing permissions
# also don't forget to add kbde in modules line in /etc/rc.conf
# to be honest, I'm not sure why we have to create /dev/kbde after each startup, but it seems that only this way it works
# maybe first check if it's needed for you, too
mknod --mode=220 /dev/kbde c 11 0 
chgrp input /dev/kbde
# changing permissions for event* -- evrouter needs that
chmod 660 /dev/input/event*
chgrp input /dev/input/event*
# g5hack ran for a few times to make sure that it'll work...
# note that I've add it to /usr/bin, you should probably put your full path here
# you probably should skip this lines, especially if you don't have logitech g5/g3/g7
g5hack /dev/usb/hiddev0 3
g5hack /dev/usb/hiddev0 3
g5hack /dev/usb/hiddev0 3


# there I use my script to start evrouter, which I have presented above
# here I map my buttons so I can use G5 thumb button as push to talk in TS
# note that I have to use it as middle button also on kde 
# you probably don't need it
xmodmap -e "pointer = 1 9 3 4 5 6 7 2 8 10 11 12"

And voila, we've got it working immediately after kde login.

User Tools

NOTE: This section is out of date, and the lomoco package may also be out of date. There is a hack for a newer logitech mice: [5]

If you use a MX* Logitech mouse, there is a tool called lomoco which will help you set the proper resolution, enable or disable smart scroll (with boot time support too!), etc. lomoco is available from the Community repository and can be installed with the following command:

pacman -S lomoco
  • Be sure to look at /etc/udev/lomoco_mouse.conf and set up the the options you want to be automatically applied when the mouse gets loaded by udev.


linuX-gamers.net How-Tos: Getting all mouse buttons working in X