Emacs: Bind Menu/App Key

By Xah Lee. Date: . Last updated: .

On most Windows 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 Windows keyboard, the ▤ Menu key sends 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

(global-set-key (kbd "C-p") 'execute-extended-command)

That's still not a good fix, because you lost the C-p.

best is to use a keyboard tool to fix at operating system level. [see Mac Keyboard Software Guide]

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 execute-extended-command 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 execute-extended-command anymore? what to do? The Windows keyboard doesn't have much convenient keys. So, you could map one of the ❖ Window key to do the execute-extended-command. Else, you can just set ▤ Menu Enter or ▤ Menu Space or ▤ Menu ▤ Menu to do execute-extended-command.

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

Keyboard Menu/App Key

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Emacs Keys

Overview

How-To

Key Tips

Emacs Pinky

Misc