This article needs additional citations for verification. (April 2013) (Learn how and when to remove this template message)
On IBM compatible personal computers, many characters not directly associated with a key can be entered using the Alt Numpad input method or Alt code: pressing and holding the Alt key while typing the number identifying the character with the keyboard's numeric keypad. Similar or extended forms of this feature are also available in many operating systems, including DOS and Microsoft Windows.
Often this is the best or only method many computer users know for entering non-ASCII characters. Many Wikipedia articles on various characters will include how to type that character using Alt codes for code page 437.
History and description
Originally on IBM PCs, the user could hold down the Alt key and type a decimal number on the keypad. The system BIOS would place the corresponding code into the keyboard buffer so that, for software using the BIOS for character input, it would look (almost) as if the code had been entered by a single keystroke. Applications reading keystrokes from the BIOS would behave according to what action they associate with that code. Some would interpret the code as a command, but often it would be interpreted as a code to be placed on the screen at the location of the cursor, thus displaying the corresponding 8-bit character from the current code page. On the original IBM PC this was CP437, see that article for a list of the numbers accepted.
Some Eastern European, Arabic and Asian computers use other hardware code pages, and DOS was able to switch between them at runtime with commands like
MODE. This causes the Alt combinations to produce different characters (as well as changing the display of any previously-entered text in the same manner). While most English systems still used CP437, another very common choice in locales using variants of the Latin alphabet was CP850, which provided more Latin character variants. There were, however, many more code pages; for a more complete list, see code page.
These numbers became so well known and memorized by computer users that Microsoft was forced to preserve them even though it used a new and different set of code pages for Windows, such as CP1252. These new code pages were called ANSI code pages by Microsoft, while the old ones were called OEM code pages. Holding Alt and typing three digits (first one non-zero) would attempt to translate the code from the 8-bit OEM code page (for example, CP850) to a matching glyph in the ANSI code page. A leading zero (0) and then a number would produce the character directly from the ANSI code page.
For instance, the combination Alt+161 would result in "í" (Latin letter i with acute accent) which is at 161 in the OEM code page of CP437 or CP850, while Alt+0161 yields the character "¡" (inverted exclamation) which is at 161 in CP1252. See CP1252 for a list of these zero-prefixed alt combinations.
When Windows later transitioned to Unicode, there was a desire to extend this to allow entry of any Unicode code point. Some applications like Word 2010 or PSPad 4.5.6 interpret alt codes larger than 255 directly as a decimal Unicode code point, but other software interprets such numbers modulus 256, or ignores any digits after the third. Although CP1252 is almost identical to the start of Unicode, this prevents entry of the code points from U+0080 to U+009F, and (more problematic) other ANSI code pages prevent entry of some very common Latin accented letters. In addition much Unicode documentation and the Character Map accessory show the code points in hex, not decimal. So a third method was developed to unambiguously enter Unicode. To enable it a user must set or create the registry key
HKCU\Control Panel\Input Method\EnableHexNumpad with type REG_SZ to value 1 and reboot or log out/in. A leading '+' then allows entry of a hex Unicode value (using the main keyboard for a–f), for example Alt++11b will produce "ě" (e with caron). This may not work in programs that have other uses for Alt plus a letter key.
The transition to Unicode actually made the older legacy Alt codes (the ones with no leading zero) more consistent, as all the glyphs in the legacy code pages have matching glyphs in Unicode, so they all work.
Third-party software can be run on Windows to replace the default keyboard handling to allow more possible ways of input, such as typing in number systems other than base 10. Modern input methods for foreign languages often have much more user-friendly methods of choosing characters, such as picking them off a popup window or using mnemonic sequences of letters, however the Alt key combinations remain very popular and often the only scheme a user knows for entering letters that are not on their keyboard.
If Num lock is disabled, attempting an Alt code may cause unexpected results in some applications, due to the controls used on the same key. For example, Alt+4 can be taken as Alt+←, causing a web browser to go back one page.
Many laptops do not have a separate numeric keypad, but may provide Numpad input by holding a modifier key (typically labelled "Fn"); thus one must press and hold both Alt and Fn keys while entering the character code.
The OEM Code Page setting changes what characters the numbers produce.
The Alt key method does not work on Linux systems and there seems to be little interest in replicating it, due to it including the dated IBM PC character encoding as part of its definition. However, numeric entry of Unicode characters is possible and it is done by the application or the UI toolkit library. This entry method has been somewhat standardized though there are slight variations:
- Hold down Ctrl+⇧ Shift and type U followed by up to eight hexadecimal digits corresponding to the character to be inserted (on main keyboard or numpad), then release Ctrl+⇧ Shift.
- Hold down Ctrl+⇧ Shift+U and type up to eight hexadecimal digits corresponding to the character to be inserted, then release Ctrl+⇧ Shift+U.
- Type Ctrl+⇧ Shift+U, then type up to eight hexadecimal digits corresponding to the character to be inserted, and then type ↵ Enter.
- Compose key for other operating systems
- Numeric character reference
- Unicode input
- Combining character
- List of Unicode characters