Emacs Hyper and Super Keys

Perm url with updates: http://xahlee.org/emacs/emacs_hyper_super_keys.html

Emacs Hyper and Super Keys

Xah Lee, 2005, ..., 2010-07-31

This page shows you how to define super and hyper keys in emacs. If you are not familiar with the basics of defining keys in emacs, see: How to Define Keyboard Shortcuts in Emacs.

Emacs supports extra modifier keys called Super and Hyper. You can map PC keyboard's Win key or the Menu key to them, or Apple keyboard's Option key.

For those curious, the Super and Hyper are actual keys on lisp machine keyboards. Lisp machine keyboards are popular around late 1980s and is used to develop emacs. For photos of lisp machine keyboards, see: Keyboard Hardware's Influence on Keyboard Shortcut Design.

Setting up Super and Hyper

Microsoft Windows

; setting the PC keyboard's various keys to
; Super or Hyper, for emacs running on Windows.
(setq w32-pass-lwindow-to-system nil 
      w32-pass-rwindow-to-system nil 
      w32-pass-apps-to-system nil 
      w32-lwindow-modifier 'super ;; Left Windows key 
      w32-rwindow-modifier 'super ;; Right Windows key 
      w32-apps-modifier 'hyper) ;; Menu key

Note: in Microsoft Windows, several keybindings with the Windows key is bound at a low level, and applications do not see them. For example, “Win+r” is for launching apps by name. (See: Microsoft Windows Keyboard Shortcuts.) There's no way around that unless you use other tools such as AutoHotkey. Even so, it may not be possible to disable “Win+l” (lock window) and “Win+u” (easy access).

(info "(emacs) Windows Keyboard")

Mac OS X

; setting Hyper and Super keys for the Mac keyboard, for emacs running in OS X
(setq mac-option-modifier 'hyper) ; sets the Option key as Hyper
(setq mac-option-modifier 'super) ; sets the Option key as Super
(setq mac-command-modifier 'meta) ; sets the Command key as Meta
(setq mac-control-modifier 'meta) ; sets the Control key as Meta

(info "(emacs) Mac Input")

Defining Shortcuts for Hyper and Super

The syntax for defining keys with the Super or Hyper modifier keys is the same as Meta and Control. Use “H” for Hyper, “s” for Super. Example:

(global-set-key (kbd "H-b") 'backward-word) ; H is for hyper
(global-set-key (kbd "s-b") 'backward-word) ; lower case “s” is for super

(global-set-key (kbd "M-H-b") 'backward-word) ; Meta+Hyper+b
(global-set-key (kbd "M-s-b") 'backward-word) ; Meta+Super+b

For more examples, see: How to Define Keyboard Shortcuts in Emacs.

Key Ghosting

Be aware that keyboard won't be able to detect certain combination of keys. This is called keyboard ghosting.

For example, suppose you have the Menu key set as Hyper, and you have “Hyper+Shift+q” as a shortcut to some command. However, Microsoft Natural Ergonomic 4000 keyboard simply does not register that combination when right shift is used. But left shift works.

For detail, see: Keyboard Ghosting; How Many Keys Your Keyboard Can Take?.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs