Configuring keyboard for “middle-paste”

The Linux desktop has two paste buffers: One that operates via the usual Ctrl-C/Ctrl-V shortcuts, and a second that can be accessed by clicking the middle mouse button on a three button mouse, or by clicking the scrollwheel on a two button + scrollwheel mouse.

On my desktop PC I use this second paste buffer frequently, but unfortunately my laptops don’t have the equivalent of a middle mouse button on their touchpads. There is a middle mouse click emulation you can configure that works by clicking both left and right buttons together, and on my older laptops this works well enough. However newer laptops have buttons that are not discrete physical buttons but clickable corners of the touchpad itself, and I find it quite challenging to simultaneously press both corners.

I cobbled together a simple work-around using xdotool, a very slick utility that allows X11 emulation of keyboard and mouse activity.

sudo apt-get install xdotool

I put this script in ~/bin/middle-mouse:


 xdotool mousedown --clearmodifiers 2
 xdotool mouseup 2

Then I set the script up to be run with Ctrl-Alt-V to parallel Ctrl-V paste. In Ubuntu’s System Settings go to Keyboard, select the Shortcuts tab, and then pick Custom Shortcuts. Click the ‘+’ and fill out the dialog with the full path to the script, as shown below:

Then click where it says ‘Disabled’ to set the accelerator keys and hit Ctrl-Alt-V.  Done!

The one quirk I’ve found in using this is with Firefox.  For some reason it prepends whatever I paste with a greater-than sign.  Anyone have an idea on how to fix that?

3 Responses to Configuring keyboard for “middle-paste”

  1. Just a thought — have you considered Shift+Insert? I believe that pastes the primary selection, which is what middle click uses. If you don’t have an Insert key, but have an Fn key, try various combinations of Fn + $normal_key. On the Thinkpad Edge E220S, Fn+i resolves to Insert, though it doesn’t seem to be documented in many places.

    Another thing is that xdotool supports chaining commands, so rather than writing a script for that, you could just use “xdotool mousedown –clearmodifiers 2 mouseup 2″ or even simpler, “xdotool click –clearmodifiers 2″.

    • bryce says:

      Ah, didn’t even think to try shift+ins. Indeed that does work, although the INS key on my laptop is placed inconveniently, so I’ll probably stick with ctrl+alt+v.

      Chaining the commands is a good idea.

  2. Pingback: Dold inklistring i Linux | Maths hörna

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>