Is there any way I can disable all mouse click events in Emacs? I tend to get focus issues when I accidentally hit my touch pad on my laptop and suddenly I'm in another Emacs window.
Asked
Active
Viewed 5,186 times
18
-
2Shouldn't you look this functionality in the os?. On my laptop, which runs ubuntu, the tapping gets muted when typing. – HMM Feb 05 '11 at 13:00
-
2I suppose that's a matter of taste. My emacs config is very portable and each of my emacsen downloads a current version from Dropbox when running. I want this to be as portable as possible so that I don't have to do os settings on a per-machine basis. – Sarah Feb 05 '11 at 14:56
3 Answers
18
Try this:
(dolist (k '([mouse-1] [down-mouse-1] [drag-mouse-1] [double-mouse-1] [triple-mouse-1]
[mouse-2] [down-mouse-2] [drag-mouse-2] [double-mouse-2] [triple-mouse-2]
[mouse-3] [down-mouse-3] [drag-mouse-3] [double-mouse-3] [triple-mouse-3]
[mouse-4] [down-mouse-4] [drag-mouse-4] [double-mouse-4] [triple-mouse-4]
[mouse-5] [down-mouse-5] [drag-mouse-5] [double-mouse-5] [triple-mouse-5]))
(global-unset-key k))

Victor Deryagin
- 11,895
- 1
- 29
- 38
-
Unfortunately this only turns off mouse-clicks in the buffer-frame you are currently visiting. The mouse works as usual when switching to another frame. – klang Feb 05 '11 at 12:02
-
2Works in all frames for me (using emacs --daemon). But it turns off only global bindings, if some mode bounds mouse clicks locally, you will need do something similar for that mode. – Victor Deryagin Feb 05 '11 at 12:07
-
This seems to be the way to go, is there a way to make the buttons on the modeline not respond to mouse as well? I've tried C-h k on some of them, but when I try clicking the buffer name, I get mouse-drag-mode-line, which seems to be not true. – Sarah Feb 05 '11 at 13:19
-
@Sarah, Different buttons bind mouse clicks by different keymaps, so you need do disable each, like this: `(setq mode-line-coding-system-map nil mode-line-column-line-number-mode-map nil mode-line-input-method-map nil)` – Victor Deryagin Feb 05 '11 at 14:47
-
See http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/1758639 for details on over-riding major and minor mode keymaps by implementing your own global minor mode. – phils Feb 05 '11 at 16:02
-
If the problem is accidental clicks from a touchpad, you probably only need to do this for mouse-1, down-mouse-1 and maybe drag-mouse-1. But you'll need to unset the bindings in more than just the global-key-map, as covered in other comments above. – JSON Feb 07 '11 at 07:55
-
And, for my fingers, [C-down-mouse-1] to disable accidental touchpad clicks while ctrl is held down. – Bill White Jul 08 '11 at 19:00
-
I had to extend this to also apply to `M-` and `C-` combos. And I used `ignore` instead of unsetting the key to avoid the `“key not defined”` message. If you're interested, I wrote about my solution here: http://endlessparentheses.com/disable-mouse-only-inside-emacs.html – Malabarba May 02 '16 at 22:50
5
I've created a package called disable-mouse, which provides local and global minor modes for disabling all mouse interaction in the current buffer or all buffers respectively.

sanityinc
- 15,002
- 2
- 49
- 43
2
Try making a M-x describe-key, and press the touch pad. Emacs will then tell you what the key is currently bound to. Unbind it and you should be ok. The touch pad should still work on the emacs frame, though.

klang
- 524
- 3
- 12
-
1Thanks very much. This doesn't quite answer the OP's question but it was perfect for what I needed - to disable a particular binding, shift-mouse-1 which was popping up an annoying buffer text menu. (global-unset-key [S-down-mouse-1]) did the trick. – Jake Oct 25 '21 at 04:06