9

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.

4 Answers 4

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, 2012 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, 2013 at 14:27
1

Mouse events carry extra information with them like their geometric properties. Using key-translation-map directly between kbd events fails due to emacs bug #28955.

I am now using the following to make super-left-click an alias for middle click:

;; super-left-click is middle click
(defun middle-click (prompt)
  (defun inner (e)
    (interactive "e")
    (setcar e 'mouse-2)
    (vector e))
  (call-interactively 'inner))

(define-key key-translation-map (kbd "s-<mouse-1>") 'middle-click)

This is the first non-trivial elisp I have written so it almost certainly could be improved somehow. I hope this helps you.

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
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-...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .