Emacs: Bind Menu/App 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-command

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 "<apps>")

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 Ban 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?

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Keys

Overview

Keybinding How-To

Key Tips

Emacs Pinky

Keybinding Design

Misc