Emacs Init: Mouse Button Syntax
Find Syntax for Mouse
- Alt+x
describe-key - press the button or scroll the wheel.
- Emacs displays the syntax in Messages Buffer
🛑 WARNING: The syntax for mouse button and wheel are different for each {Microsoft Windows, Linux, Mac}, also depends on what mouse, trackpad, etc you are using. This means, if you created a emacs config for mouse on one operating system, it may not work in another operating system.
Sample Code for Binding Mouse
;; sample setting for mouse button and wheel ;; Emacs 29 syntax ;; For emacs 28, use global-set-key (cond ((eq system-type 'windows-nt) (keymap-global-set "<mouse-4>" 'describe-char)) ((eq system-type 'darwin) ; Mac (keymap-global-set "<mouse-4>" 'describe-char)) ((eq system-type 'gnu/linux) (keymap-global-set "<mouse-8>" 'describe-char))) (keymap-global-set "M-<wheel-up>" 'previous-buffer) (keymap-global-set "M-<wheel-down>" 'next-buffer)