Next: , Previous: Windows HOME, Up: Microsoft Windows

G.6 Keyboard Usage on MS-Windows

This section describes the Windows-specific features related to keyboard input in Emacs.

Many key combinations (known as “keyboard shortcuts”) that have conventional uses in MS-Windows programs conflict with traditional Emacs key bindings. (These Emacs key bindings were established years before Microsoft was founded.) Examples of conflicts include C-c, C-x, C-z, C-a, and W-<SPC>. You can redefine some of them with meanings more like the MS-Windows meanings by enabling CUA Mode (see CUA Bindings).

The <F10> key on Windows activates the menu bar in a way that makes it possible to use the menus without a mouse. In this mode, the arrow keys traverse the menus, <RET> selects a highlighted menu item, and <ESC> closes the menu.

By default, the key labeled <Alt> is mapped as the <META> key. If you wish it to produce the Alt modifier instead, set the variable w32-alt-is-meta to a nil value.

MS-Windows reserves certain key combinations, such as Alt-<TAB>, for its own use. These key combinations are intercepted by the system before Emacs can see them. You can use the w32-register-hot-key function to allow a key sequence to be seen by Emacs instead of being grabbed by Windows. This functions registers a key sequence as a hot key, overriding the special meaning of that key sequence for Windows. (MS-Windows is told that the key sequence is a hot key only when one of the Emacs windows has focus, so that the special keys still have their usual meaning for other Windows applications.)

The argument to w32-register-hot-key must be a single key, with or without modifiers, in vector form that would be acceptable to define-key. The meta modifier is interpreted as the <ALT> key if w32-alt-is-meta is t (the default), and the hyper modifier is always interpreted as the Windows key (usually labeled with <start> and the Windows logo). If the function succeeds in registering the key sequence, it returns the hotkey ID, a number; otherwise it returns nil.

For example, (w32-register-hot-key [M-tab]) lets you use M-TAB normally in Emacs; for instance, to complete the word or symbol at point at top level, or to complete the current search string against previously sought strings during incremental search.

The function w32-unregister-hot-key reverses the effect of w32-register-hot-key for its argument key sequence.

By default, the <CapsLock> key only affects normal character keys (it converts lower-case characters to their upper-case variants). However, if you set the variable w32-capslock-is-shiftlock to a non-nil value, the <CapsLock> key will affect non-character keys as well, as if you pressed the <Shift> key while typing the non-character key.

If the variable w32-enable-caps-lock is set to a nil value, the <CapsLock> key produces the symbol capslock instead of the shifted version of they keys. The default value is t.

Similarly, if w32-enable-num-lock is nil, the <NumLock> key will produce the symbol kp-numlock. The default is t, which causes <NumLock> to work as expected: toggle the meaning of the keys on the numeric keypad.

The variable w32-apps-modifier controls the effect of the <Apps> key (usually located between the right <Alt> and the right <Ctrl> keys). Its value can be one of the symbols hyper, super, meta, alt, control, or shift for the respective modifier, or nil to appear as the key apps. The default is nil.

The variable w32-lwindow-modifier determines the effect of the left Windows key (usually labeled with <start> and the Windows logo). If its value is nil (the default), the key will produce the symbol lwindow. Setting it to one of the symbols hyper, super, meta, alt, control, or shift will produce the respective modifier. A similar variable w32-rwindow-modifier controls the effect of the right Windows key, and w32-scroll-lock-modifier does the same for the <ScrLock> key. If these variables are set to nil, the right Windows key produces the symbol rwindow and <ScrLock> produces the symbol scroll.

Emacs compiled as a native Windows application normally turns off the Windows feature that tapping the <ALT> key invokes the Windows menu. The reason is that the <ALT> serves as <META> in Emacs. When using Emacs, users often press the <META> key temporarily and then change their minds; if this has the effect of bringing up the Windows menu, it alters the meaning of subsequent commands. Many users find this frustrating.

You can re-enable Windows's default handling of tapping the <ALT> key by setting w32-pass-alt-to-system to a non-nil value.

The variables w32-pass-lwindow-to-system and w32-pass-rwindow-to-system determine whether the respective keys are passed to Windows or swallowed by Emacs. If the value is nil, the respective key is silently swallowed by Emacs, otherwise it is passed to Windows. The default is t for both of these variables. Passing each of these keys to Windows produces its normal effect: for example, <Lwindow> opens the Start menu, etc.1

The variable w32-recognize-altgr controls whether the <AltGr> key (if it exists on your keyboard), or its equivalent, the combination of the right <Alt> and left <Ctrl> keys pressed together, is recognized as the <AltGr> key. The default is t, which means these keys produce AltGr; setting it to nil causes <AltGr> or the equivalent key combination to be interpreted as the combination of <CTRL> and <META> modifiers.


Footnotes

[1] Some combinations of the “Windows” keys with other keys are caught by Windows at a low level in a way that Emacs currently cannot prevent. For example, <Lwindow> r always pops up the Windows ‘Run’ dialog. Customizing the value of w32-phantom-key-code might help in some cases, though.