Linux: Make Your Scroll Wheel Double Click

12/10/2008 I’ve verified that this also works for Ubuntu 8.10 (Intrepid Ibex). I also made a couple of cosmetic changes in places where line breaks weren’t appearing properly. Entering the information without the right line breaks prevented the changes from working properly.

When I made the switch to Linux at work, I knew that I would have to make some adjustments to my workflow and retrain my muscle memory for certain tasks. To be honest, I really thought there would be many more than I’ve run into so far. One of those that I have run into involves the functionality of the scroll wheel button on my mouse.

On Windows (and also on Mac, I think), I use drivers that allow me to use the scroll wheel button to provide single-click access to the double-click action. I love that convenience and missed it after the switch. Moreover, the default Ubuntu action of pasting when I clicked the scroll wheel button left me with a lot of interesting and unintended results as well as an unnaturally smooth Ctrl+Z motion. The latter reason prompted me to dig around. I mean, it has to be possible, right?

It is possible, but it was more difficult to find that I would have thought. In my mind, everyone should be using this shortcut so there should be lots of information out there. Except that there’s not, so maybe I’m one of only a few who prefer this use for the scroll wheel button. Either way, I was finally able to track down a solution in the Ubuntu Forums that was easy to implement and works beautifully.

The original thread message contains a lot of useful information, but is more long-winded than I want next time I need to remember how to do this, so here’s the distilled version:

The steps below assume that you have a mouse with a scroll wheel and that the scroll wheel and its button are recognized by the operating system. A “recognized” scroll wheel will probably, well, scroll. A “recognized” scroll wheel button may perform a paste operation.

Install xautomation and xbindkeys Packages

Open a terminal window and type:

$ sudo apt-get install xautomation xbindkeys

Determine the Scroll Wheel Button Number

At your shell prompt, enter:

$ xev

A small window should open. Move the mouse into that window and, ignoring all of the output that is generated during the movement itself, click the scroll wheel button. The output generated by the click is also verbose, but the important part should look something like this:

ButtonRelease event, serial 28, synthetic NO, window 0x3e00001,
   root 0x61, subw 0x3e00002, time 13989572, (43,42), root:(1138,881),
   state 0x100, button 2, same_screen YES

In the third line, the button is identified on my mouse as button 2. That number may be different for your mouse. Make a note of the button number. Seriously. Write it down. Now.

Edit the xbindkeys Config File

Technically, this is a create and edit operation, but you get the idea.

$ vi ~/.xbindkeysrc

In that file, add the following lines:

"/usr/bin/xte 'mouseup 2' 'mouseclick 1' 'mouseclick 1' &"
b:2 + Release

Replace the “2” values with the button number you found above (you did make a note of it, didn’t you?) if the scroll wheel button isn’t the second button on your mouse. In the second line, you can remove the “ + Release” portion if you want the double click to be recognized on “mousedown” as opposed to “mouseup”.

Test

To test, run xbindkeys in the foreground so that any errors will be output to the terminal display:

xbindkeys -n -v

Now ensure that the double click action is responding as expected. If it is, then kill the foreground process by typing Ctrl+C and restart xbindkeys as a background process:

xbindkeys &

Set xbindkeys to Start When X Loads

I did this using the GUI by going to System > Preferences > Sessions > Startup Programs. Add a new startup item as:

xbindkeys Startup Details

These steps worked brilliantly on Ubuntu 8.0.4.1. If you’re waiting for me to say that your mileage may vary, well, I guess I just did.

For those who want to read more, the forum message really is full of good information.

Subscribe7 Comments on Linux: Make Your Scroll Wheel Double...

  1. Lin Freeman said...

    Hi,
    Since I completely agree about double clicking, I followed Rob’s suggestions and, of course, they worked perfectly. Worked, that is, except for the final step: after which the double-click should last through a reboot. That doesn’t work for me; after a reboot the wheel is simply a single click until I open a console and enter “xbindkeys &” again . Anyone have any suggestions?
    Thanks,
    Lin

  2. Rob Wilkerson said...

    Hey Lin –

    Sorry about that, I should have updated the post. I had the same problem and the issue is the “&” in the startup command. Remove that and you should be golden. I’ll take a new screenshot and make the appropriate update.

    Thanks for reminding me and apologies for the misleading information.

  3. Larry said...

    Worked like a charm for me in 8.10. Thanks a lot for posting this, Rob!

  4. Mark said...

    Works perfect, but unfortunately doesn’t survive an Ubuntu update. So i had to do this the second time ;)

    Thank you for posting such a detailed guide.

  5. Andrey said...

    Thanks a lot. It works on Xubuntu 9.04

  6. r_ said...

    Thanks, Rob. Applying the knowledge I gained from your excellent explanation, and after looking at the help listing for xte, I was able to make any button do things like go back/forward between browser pages, go home/end of page, pageup/pagedown, etc. If only all tips on help forums were as clear as yours…

    Thanks again

  7. Steve said...

    I used this tip on my wife’s computer; it worked great on 8.04 but not on subsequent versions (although Rob said it worked for him on 8.10). The problem might be that starting with 8.10, Nautilus seems to have its own (undocumented?) scroll wheel click behavior: a single click of the scroll wheel behaves like a double-click when Nautilus is in Icon view (although scroll wheel clicking a folder opens it as a new tab rather than replacing the contents of the current window). A scroll wheel click doesn’t appear to do anything in List view.

    If anyone has any insight into this I’d love to disable the default behavior and use Rob’s tip (or something similar) instead.

    Thanks!