Emacs: How to Define Menu Key

By Xah Lee. Date: . Last updated: .

On most PC keyboards, there's the ▤ Menu key, also known as App key. This page shows you how to use that key in emacs, on linux or Mac or Windows.

pc keyboard menu key 86821
the ▤ Menu key (to the right of Alt).

Menu Key in Linux

In Linux GNU emacs, by default, ▤ Menu key invokes execute-extended-commandAlt+x】.

Under linux, the menu key has the syntax (kbd "<menu>")

For example,

(global-set-key (kbd "<menu>") 'execute-extended-command)

Menu key on Microsoft Windows

On Microsoft Windows, by default, it does nothing.

Under Windows, the menu key has the syntax (kbd "<app>")

You can set it to do execute-extended-command, like this:

(when (string-equal system-type "windows-nt")
  (global-set-key (kbd "<apps>") 'execute-extended-command))

Menu key on Mac

On Mac OS X, if you are using a PC keyboard, the ▤ Menu key will send 【Ctrl+p】 by default.

How to fix menu key on the Mac?

You can workaround by:

;; make Ctrl+p send the menu/app key
(define-key key-translation-map (kbd "C-p") (kbd "<menu>"))

or

Set a command to it like this (global-set-key (kbd "C-p") 'execute-extended-command)

That's still not a good fix, because you lost the C-p, but i don't know the answer.

Might try with these Mac tools Mac: Key Remapping and Keybinding Tools

How to make Mac's ⌘ command or ⌥ option key to send the ▤ Menu key?

To make Mac's ⌘ command or ⌥ option key to send the ▤ Menu key, use the util Seil (aka PCKeyboardHack). See: Mac: Key Remapping and Keybinding Tools.

But it'll still send out the C-p. So you need to remap C-p described above.

Make the Menu as Leader Key

Best is to set ▤ Menu key as the lead key of key sequences for emacs's hundreds of commands. [see Banish Key Chords]

Example of key sequence starting with the ▤ Menu key.

;; on Linux, the menu/apps key syntax is <menu>
;; on Windows, the menu/apps key syntax is <apps>
;; make the syntax equal
(define-key key-translation-map (kbd "<apps>") (kbd "<menu>"))

(progn
  ;; define set of key sequences
  (define-prefix-command 'my-leader-key-map)

  (define-key my-leader-key-map (kbd "RET") 'execute-extended-command)
  (define-key my-leader-key-map (kbd "<menu>") 'exchange-point-and-mark)

  (define-key my-leader-key-map (kbd "'") 'quoted-insert)

  (define-key my-leader-key-map (kbd "2") 'delete-window)
  (define-key my-leader-key-map (kbd "3") 'delete-other-windows)
  (define-key my-leader-key-map (kbd "4") 'split-window-below)
  (define-key my-leader-key-map (kbd "5") 'split-window-right)

  (define-key my-leader-key-map (kbd "7") 'dired-jump)
  (define-key my-leader-key-map (kbd "9") 'ispell-word)

  (define-key my-leader-key-map (kbd "a") 'mark-whole-buffer)
  (define-key my-leader-key-map (kbd "b") 'end-of-buffer)

  (define-key my-leader-key-map (kbd "d") 'beginning-of-buffer)
  (define-key my-leader-key-map (kbd "g") 'isearch-forward)

  (define-key my-leader-key-map (kbd "k") 'yank)
  (define-key my-leader-key-map (kbd "l") 'recenter-top-bottom)
  (define-key my-leader-key-map (kbd "m") 'universal-argument)

  (define-key my-leader-key-map (kbd "p") 'query-replace)

  (define-key my-leader-key-map (kbd "z") 'comment-dwim))

;; make the menu key as leader key
(global-set-key (kbd "<menu>") 'my-leader-key-map)

Why should you use the menu key?

Setting the ▤ Menu key for M-x is quite convenient. You'd know if you've used it on linux.

but, emacs has hundreds of commands starting with Ctrl+x. It'd be nice, if all these are just a key sequence of 3 keys. That way, you don't have to hold down a key on the corner.

So, we can use the ▤ Menu as a lead key for sequences.

But you don't have a single key for M-x anymore? what to do? The standard PC keyboard doesn't have much convenient keys. So, you could map one of the ❖ Window key to do the M-x. Else, you can just set ▤ Menu Enter or ▤ Menu Space or ▤ Menu ▤ Menu to do M-x.

How to design key sequence to replace all C-x?

you can see example design here Emacs: Xah Fly Keys

Use of Menu Key Outside of Emacs

What's the Use of the ▤ Menu/App Key?

Emacs Keybinding How-To Topic

  1. Emacs: How to Define Keys
  2. Emacs: Change Major Mode Keys
  3. Emacs: Change Minor Mode Keys
  4. Emacs: Fix Minor Mode Key Priority
  5. Emacs: Define Key Sequence
  6. Emacs: How to Bind Super Hyper Keys
  7. Emacs: How to Define Menu Key
  8. Emacs: Remapping Keys Using key-translation-map
  9. Emacs: Bind Number Pad Keys
  10. Emacs: How to Set Mouse Buttons
Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs