How can I attach a middle button press to a specific key in my laptop?
I can do middle-button if I tap on the top right corner of the touchpad, but I would like to associate it to a key, like the "windows" key or the "menu" key.

Is there a way to do that?

The current answer doesn't work for Ubuntu 11.10 with a classic gnome-failsafe desktop. I would need someone to figure out how can this be done for the updated Ubuntu version.

Then from Dash search for Startup Applications or if using Gnome Classic - Applications - Other - Startup Applications

Add a new Startup Applications entry

The command should be:

bash -c "sleep 5 && ~/remapkeys"

The command sleeps for 5 seconds to allow your desktop to appear before running your new script - if your desktop doesnt appear within 5 seconds (maybe you are using a slow netbook?) then increase this timeout to 10 or 15 seconds.
Logout and login to test.

Can I ask, after following these steps, should be binding be permanent or should I put it somewhere so that it's loaded every time I reboot?
–
719016Oct 28 '11 at 15:51

certainly not permanent - I would add the statements to a script and run as part of startup applications so it runs on login. Does the answer work for you - it did in my testing...
–
fossfreedom♦Oct 28 '11 at 15:59

I'd note, for others (since I found this several times while looking for my own mouse) that some Logitech mice have a few buttons (on my MX1100, they were by default "DPI +/-" buttons) that do not send a signal to the USB receiver.

It is possible to override this and have the mouse report the button presses to your mouse driver, but the process is not even close to user-friendly (or even easily replicable, since it appears to be different for each mouse). The "lomoco" package will apparently work for some users, but has not been updated for newer mice in a while.

You can create a custom shortcut for that under Preferences -> Keyboard Shortcuts (or 'Keyboard Shortcuts' from the Unity search). Click 'Add', enter a name and the above command and click 'Apply'. Scroll to the bottom and set a shortcut as you would for any other action.

When I tried this, I wasn't able to bind the action to just the Windows key. You can try it by doing the following, but there seems to be a bug that prevents this from working:

Open a terminal and run

gconf-editor

Hit Ctrl+f, select the 'Search also in key values' box and enter the following to the search box:

xte 'mouseclick 2'

There should be only one result in the bottom pane. If there's more, select the one that contains '/desktop/gnome/keybindings/custom*/action' in its name. In the top-right pane, enter '' (without quotes) next to the 'binding' field. If you get the same result that I did, all your window appearances will change, and the new keybinding won't do anything. Change that back to whatever it was (or make it blank) and open Appearance (Preferences -> Appearance or 'Appearance' under unity search). That should fix the issue.