How to map your mouse on Linux

The Linux desktop is unfortunately not a mainstream operating system, and so peripherals manufacturers don't care much whether those cool extra side buttons (or whatever else) of our mouse works as intended or not. Thankfully, Linux is a powerful system that allows users to set things as they like, so here is a quick guide on how to map your mouse.

First, make sure to install the packages “xbindkeys” and “xautomation”. Then open a terminal and type “xev” and press enter. This little tool is essential for the process of mapping your mouse as it creates a small window and monitors mouse movement and actions on it. Take your cursor above this window and start clicking your mouse buttons to determine what number is assigned on each one.

If you got overwhelmed by the volume of information that is printed on the terminal with this command, you can alternatively use the “xev |grep button” to limit the terminal output on the mouse button clicks only.

Now that we know what button corresponds to what number we can proceed to the mapping by navigating to the etc/X11/xorg.conf and opening the configuration file for editing. Note that to edit and save your changes to the file, you will need to do it as root. If you can't find an xorg.conf file in the indicated location, don't be alarmed as this is a common thing for Ubuntu-based distributions nowadays. You can generate an xorg.conf file by doing the following:

  1. Switch to console mode by pressing “Alt+Ctrl+F1” simultaneously
  2. Kill the x server that is still active by typing “sudo service lightdm stop” and pressing enter
  3. Generate the xorg.conf file by typing “sudo X -configure” and pressing enter
  4. Get back to the desktop environment by typing “sudo start lightdm” and pressing enter
  5. Locate the newly created file and rename it to “xorg.conf
  6. Move the renamed configuration file to etc/X11

Now open the file and locate the part that concerns the mouse device. It should be something like what is shown between lines 29 and 34 in the following screenshot.

The particular lines that need our attention are those containing the word “Protocol” and the “ZAxisMapping”. The protocol refers to what protocol is used for the communication of your device with your system so it may be a “PS/2”, a “BusMouse”, an “Explorer PS/2, a “MouseSystems”, a “USB” or “Logitech” protocol. There are many protocols that you can enter on this line, and depending on your mouse model you may need to research a bit, but the only reason to change the protocol is if you have any buttons that don't work. If all of your buttons outputs a number on the “xev” command, then you are good to proceed to the configuration of the “ZAxisMapping” line.

This line refers to the functionality of your mouse's scroll wheel and in my case it contains four numbers as my mouse wheel also has a back/forward ability. If yours doesn't, you should see two numbers corresponding to up/down scrolling action. If your wheel isn't working, you should change the numbers on this line with the numbers that were generated when your scrolled your mouse wheel during the “xev” command testing. You may do that, save the file, restart X and the wheel should work now.

Getting to the mouse button mapping, we need to use the “xmodmap” utility. Open a terminal and type

xmodmap -e “pointer = 1 4 3 7 9 5 8 2”

The numbers are not random, as each entry corresponds to a function. You should first consider that the first position corresponds to the left-click, the second to the middle click, the third to the right click, fourth and fifth to up and down scrolling etc. So, if your middle click isn't working, you should use the middle click outputted number from “xev” on the second position in the xmodmap command. If you are left handed, you may swap keys 3 and 1 to correspond to invert right-left clicking etc. By typing:

xmodmap -pp

And pressing enter on a terminal, you can see how many physical buttons are defined for your device and what corresponds to which entry.

Configuring your mouse may prove to be a tricky process, especially if you've bought one of those “Windows 8 and 10” mouses that send keyboard commands and complicate things even more. Trying various configurations with xmodmap will almost always get you there sooner or later, but don't forget to backup your original xorg.conf file in case things go wrong. For mouse model-specific information and configuration help, visit HowToForge forums as chances are you're not the only one using a “nasty” mouse.

Share this page:

6 Comment(s)

Add comment


From: stan

I run a 6.00$ mouse from a local dollar store. I only run Linux, What I do to make them work is shut off the mouse--re-boot and turn on the mouse again. It finds it every time. I run Lubuntu


From: jelabarre59

I tried this with the Logitech TouchMouse T400.  The so-called "middle buttons" do not respond correctly to this utility.  If you click on the upper "middle" button (top part of the touch zone, it just brings up the program menu (whatever Cinnamon desktop would call their equivalent of the MSWin "Start Menu").  Clicking on the bottom part of the touchzone just minimizes all the windows and shows the desktop. 

So I would put out a STRONG suggestion that anyone who runs or would ever run Linux should stay far away from the Logitech T400 Zone Mouse.  It is a waste of your money, and absolutely a waste of your time trying to make the P.o.S. at all usable in Linux.  And Logitech has been informed of the failure of the mouse on Linux, and steadfastly refuse to address the problem.

From: Brucey

I try this with my mouse Logitech Kinzu v2, and there are some problem with my middle button scroll. It won't navigate as it should be.

From: Scott

None of this applies to Fedora.


From: ian

Sorry, but I think you're a bit behind the times.  Linux keeps moving.

Generating an xorg.conf is very noughties.  If you're going to play with mouse settings, look in the xorg.conf.d folder, either in /etc/X11 or in /usr/share/X11.  xorg.conf is autogenerated as people do like to plug in different inputs and monitors these days, and so xorg.conf has to be flexible enough to accomodate this.  If you generate an xorg.conf you'd better not be plugging an extra monitor in, change your mouse, or any other modern trivialities!!

From: Alex

I stumbled upon your post and I really love the theme in the screenshots! What theme is this and is it for Ubuntu?