How to Customize Extra Mouse Buttons in Linux

Ryan D. Lang
Jun 28, 2011
Linux
|
15

If you are using a mouse, trackball, or touchpad with extra buttons in Windows, chances are the manufacturer has created software to configure the buttons. Rarely do they create such software for Linux. Btnx (button x) can be used to configure the mouse buttons in Linux for a variety of pointing devices.

With a three button mouse, typically people keep the default settings. With a five button mouse, the extra two buttons often go unused. The default is that they typically are used to go back and forward in web browsers and file managers. This is not as handy in other programs. Other functions might be more useful; the user should decided what they need. For example, I would rather use the extra buttons to copy and paste text. Enter btnx.

Using Btnx

To install btnx, search for it in Ubuntu's Software Center (found in the Application menu). Alternatively, you can install it from the command line.

sudo apt-get install btnx

Now you can access btnx from:

Applications > System Tools > btnx

This will bring up a GUI dialog box for you to configure you mouse. From here, click "Detect mouse & buttons" and follow the steps. It will have you test your mouse and label the buttons. Don't forget to add your scroll wheel. It is an extra step compared to manufacturers' software, but it only takes a minute or two. Next, click on the "Buttons" tab to configure what each button does. Usually, it is the extra mouse buttons that are the best to customize, but any can be changed.

In this case, I set the keycode on "Button-1" (named by me) to "C" and the modifier to "Ctrl." Since this is just a case of simulating "ctrl+c" to copy something, left or right control keys are irrelevant. Naturally, I set the "Button-2" as "ctrl-v" for paste. Page Up & Page Down would also make sense. Options are not limited to key combinations. Programs and other buttons can be set as well. A wide array of functions are available for someone to choose from.

extra mouse buttons linux

Make sure to click the "Enabled" check box. To apply the changes, restart btnx from the "Configurations" tab. If a change does not seem to be taking place, try restarting btnx or your computer.

Note: The homepage and the help files were not available. For clarification and program details, use the man pages from the Wayback Machine.

Problems and Issues

In tests, while the remapping worked, a curious side effect evolved: the buttons now work as both copy & paste and forward & back. This made them useless in websites. Further research lead to a fix: xinput. The program will let you swap or disable mouse buttons, among other things. It should come with Ubuntu and other types of Linux, but it can be installed from the terminal:

sudo apt-get install xinput

Once installed, you need to use it to list and show devices:

xinput list

You should see your pointing device listed. Look for your manufacturer's name. If the name appears twice, then you need to use the "id" number in place of the name. Once you have found this information, you can disable the extra button functionality with the following line:

xinput set-button-map "Your mouse name" 1 2 3 4 5 6 7 0 0

Now, your mouse should work as intended. Btnx will still know you are pressing the buttons, so the remap will still work. If you have problems, try running through "Detect mouse & buttons" again to make sure they were set correctly. Note: You may have to do this each time you customize the buttons.

Closing

It took some time to find the answers, but I now have perfectly functional copy & paste buttons on my trackball. These solutions where found in the forums at ubuntuforums and pinoygeek. With luck, you will not have the problems that I ran into. If you do, I hope this article saves you the trouble of having to research the solution. Please feel free to share how you remap your mouse in the comments.

Advertisement

Previous Post: «
Next Post: «

Comments

  1. electr0n said on March 15, 2021 at 8:36 am
    Reply

    To be honest, my workflow and productivity increased vastly when I moved to a tiling window manager (xmonad) from which I customized the keybindings to my liking and mouse usage is minimal. Move focus from one window to the next? mod+j/k send window to screen 1 or 2 or 3 mod+w+e+r (1 2 or 3) launch terminal? mod+shift+enter. I don’t know why I had not done it sooner. Just something to look into

  2. Greg said on October 10, 2018 at 2:15 am
    Reply

    btnx is not in the trusted repositories any more, but can be found here at “Other versions in untrusted archives”: https://launchpad.net/ubuntu/+source/btnx

  3. NDrewNYC said on April 20, 2014 at 5:30 am
    Reply
  4. NDrewNYC said on April 19, 2014 at 7:05 pm
    Reply

    Im dying without a simple gui 5 button mouse control program in linux. As the previous poster noted – there is no such thing as btnx program !!! WTF?

  5. Elemer said on April 3, 2014 at 10:34 am
    Reply

    There is no btnx in Ubuntu,
    Neither is a BUtton X app in Software Center.
    I guess nothing losts for ever (You posted this 3 years ago) – ( I write this in 2014-Apr-3)

  6. jlx said on December 16, 2012 at 1:47 pm
    Reply

    Well no btnx in xubuntu was hoping i could abandon swinedows for gaming but it seems i still have to go back to that horrible OS.. oh well ima dedicate an hour or 2 more to find a solution for this lol maybe there is a btnx bin or similar out there and i can just get it done in 5 mins (they do say hope is the last to go lol)

  7. v said on December 28, 2011 at 9:18 pm
    Reply

    Thanks, this was very helpful. As a side comment to previous posts, I use the extra buttons on my mouse for SPACE and ENTER, so I don’t have to constantly remove my hand from my mouse to simply hit those keys. (I know I could use my left for the space, whatever, :P ) This speeds up simple windows operations and some typing and navigation requirements. (Windows/Linux)

    Again, thanks for this tutorial, it’s greatly appreciated. :)

  8. Not Bill said on August 28, 2011 at 7:57 pm
    Reply

    how do you configure a double-click?

  9. Gar said on August 2, 2011 at 9:32 pm
    Reply

    Now, it would be awesome if we could get the keys to change what they do based on the application the mouse is currently focused on. I have a Logitech MX Performance Mouse and on windows, the logitech software allows me to set different tasks for the buttons depending on which application was in focus. So, in a browser, the forward/back buttons were forward and back but when I was in eclipse or in vim, I changed the back/forward buttons to do vim jumps ( and ) and eclipse jumps in eclipse.

    1. Gary said on August 2, 2011 at 9:33 pm
      Reply

      oops, I guess you can’t edit posts. But it was supposed to be vim jumps (c-o and c-i) but I had angle brackets and it ate them.

  10. Scott said on June 30, 2011 at 7:35 pm
    Reply

    A better argument still is “Why move your hand to the mouse when keeping it on the keyboard saves time?” Dedicating mouse buttons to work around a rare problem just means you will rarely benefit by using them. And a single mouse button press still takes more time than pressing two keys on the keyboard since to do so you have to move your hand to and from the mouse. Of course, if your hand lives there already, that isn’t a problem. Web browsers typically encourage that, but if you are going to spend time and energy moving your hand to the mouse, or reprogramming its buttons, you should get a bigger return on that investment than you get from a simple copy and paste. That’s why I suggested a more complex action be associated with them. That way, even though you move your hand away from the keyboard, the extra time it takes for that is made up for by the complexity of the operation it initiates.

    On a slightly different tangent, the web browser interface is a problem for keyboard users. Web browsers are notoriously mouse-centric, and needlessly so. They are not designed for editing or composing text, so it makes no sense for browser designers to virtually ignore the entire keyboard and focus almost exclusively on the mouse for user interaction. It’s as if they think typing text is the only thing a keyboard is good for. Vimperator and Pentadactyl help with that. They have figured out how to handle text imput when needed, but you must be familiar with vi or Vim to take advantage of them. Perhaps someone will develop a similar add-on that emulates WordStar for those who prefer it. (I’m surprised that hasn’t happened.) It is rather handy, though, to be able to use the keyboard to navigate within a web page, select text, and paste it somewhere else without the damned mouse insinuating itself into your work flow. Not to mention link navigation and tab switching by keyboard.

    :wq

  11. Scott said on June 28, 2011 at 4:56 pm
    Reply

    Why bother with a five-button input device when there is a far more flexible 104 key input device included with every computer. Are mouse users really that desperate to keep their hands away from the keyboard? What is amusing is that in your example you remap your mouse buttons to common keyboard shortcuts that are within easy reach of your left hand. What have you gained? At least remap them to something harder to type, like performing a Google search from any application on selected text or copying a file to your Dropbox account. That would be much more interesting and useful, and might make the mouse a less useless space waster.

    :wq

    1. Ryan D. Lang said on June 28, 2011 at 7:23 pm
      Reply

      Why use two keys when one button will do?

      A better argument would be: “Why do this remap in Linux when you can just select text and middle click to paste without copying?” This remap actually is a work-around for when the Linux trick fails in certain rare instances.

      When selecting text, I sometimes (not always) find it faster to use a mouse (esp. if you double click, holding the second click). This is especially true for webpages.

      That said, I actually prefer the keyboard. I believe in learning as many keyboard shortcuts as possible; they are faster that a GUI typically. As a draftsman, I needed both. To enter commands, I used the keyboard; the select objects, I used the trackball. I wish I had extra buttons on that trackball. I would have found uses for them.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.