8

I use a macbook pro and thus am subjected to a trackpad with one button. I can, of course, do mouse-1 by clicking and mouse-3 by clicking with two fingers, but there isn't much I can do about a middle click (mouse-2).

I'm surprised this hasn't bit me before, but I only recently started being annoyed by the lack of a middle mouse button. In particular, I've started using ERC and flyspell, both of which have functions that require a middle click.

I've googled extensively but haven't been able to find a way to do this. Here is precisely what I'd like to do:

In Emacs, I'd like for Emacs to view command+mouse-1 as if it were mouse-2. Basically, I'd like a way to rebind <s-mouse-1> to trigger a <mouse-2> event. Is this possible?

If it is helpful at all, I'm using one of the Emacs 24 builds of Cocoa Emacs and I'm running Lion on a '08 era macbook pro.

5

Try this:

(define-key key-translation-map (kbd "<C-down-mouse-1>") (kbd "<down-mouse-2>"))

For more information, read Translation Keymaps.

2
  • 2
    When I do this and then try to use a cmd-click for flyspell it complains with the following error message: flyspell-correct-word must be bound to an event with parameters. Any suggestions?
    – Alex R
    Feb 18 '12 at 1:08
  • 1
    Weird, I saw the same error message. The following works for me though: (global-set-key [M-down-mouse-1] 'flyspell-correct-word)
    – edwardw
    Mar 27 '13 at 14:27
0

Trey's suggestion did not work for me but this did:

(define-key key-translation-map (kbd "<C-mouse-1>") (kbd "<mouse-2>"))

This maps control-left-click to middle-click (the down- piece didn't work for me).

Note to Alex R: C-... is control-, not command- (which is lowercase s-...)

0

This isn't so much of a solution as a workaround, but I'm currently trying the (open source) MiddleClick app which adds middle-click functionality all across the system by triggering a middle-click when you do a three-finger-tap.

The only problems are that you can press middle-click accidentally by touching three fingers on the trackpad every now and then, which has been somewhat annoying. There are also obviously the system trackpad bindings (e.g., App Expose or Mission Control) that can conflict with the three-finger-tap if you don't make the corresponding scrolling motion pronounced enough. You could probably fix these conflicts by tweaking the sources, as it appears that there are no settings in the running app itself.

You can install MiddleClick via homebrew as well:

brew cask install middleclick

EDIT:

It turns out that the three-finger-tap behavior of MiddleClick is rather annoying and unusable, for me at least. Also, trying to modify the sources for better behavior proved to be more trouble than it's worth, as MiddleClick makes use of MultitouchSupport.framework, which is private and requires reverse-engineering to make sense of its functions' parameters. Unfortunately, I don't have time for that right now, esp. over something so basic. However, I did find BetterTouchTool which implements the same basic functionality but provides much more customizability. It's not free, but it's only $3 and moreover it works fine with the Magic Trackpad 2, which can't be said for the similar app that I also tried, MagicPrefs.

BetterTouchTool can also be installed via homebrew:

brew cask info bettertouchtool

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.