18

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.

2
  • 2
    Shouldn't you look this functionality in the os?. On my laptop, which runs ubuntu, the tapping gets muted when typing.
    – HMM
    Feb 5, 2011 at 13:00
  • 2
    I 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 5, 2011 at 14:56

3 Answers 3

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))
8
  • 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 5, 2011 at 12:02
  • 2
    Works 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. Feb 5, 2011 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 5, 2011 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) Feb 5, 2011 at 14:47
  • See stackoverflow.com/questions/683425/… for details on over-riding major and minor mode keymaps by implementing your own global minor mode.
    – phils
    Feb 5, 2011 at 16:02
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.

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.

1
  • 1
    Thanks 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, 2021 at 4:06

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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