|This article needs additional citations for verification. (April 2013)|
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 codepage 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 codepage. Without other software loaded, this is the so-called hardware codepage, which is codepage 437 for original IBM PCs and most other computer systems using English. Some Eastern European, Arabic and Asian computers use other hardware codepages, however.
When an operating system like DOS was used, it became possible to override the hardware codepage with a variety of other codepages and even switch between them at runtime with commands like
MODE. While most English systems still used codepage 437 under DOS, another very common choice in locales using variants of the Latin alphabet was codepage 850, which provided more Latin character variants than codepage 437. There were, however, many more codepages; for a more complete list, see codepage.
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 codepages for Windows, such as Codepage 1252. These new codepages were called ANSI codepages by Microsoft, while the old ones were called OEM codepages. Holding Alt and typing three digits (first one non-zero) would attempt to translate the code from the 8-bit OEM codepage (for example, codepage 850) to a matching glyph in the ANSI codepage. A leading zero (0) and then a number would produce the character directly from the ANSI codepage.
For instance, the combinationAlt+161 for codepoint 161 would result in "í" (Latin letter i with acute accent) with an OEM codepage setting of e.g. 437 or 850. On a Windows system using codepage 1252 as ANSI codepage, Alt+0161 yields the character "¡" (inverted exclamation) which is at 161 in ANSI codepage 1252.
When Windows later transitioned to Unicode, the 0-leading codes had become so well known as well that a third method needed to be invented to produce Unicode codepoints. Although codepage 1252 is quite close to the start of Unicode and it would seem logical to just allow larger numbers to be typed, other international sets did not match, and some users were accustomed to numbers larger than 255 being translated modulus 256. Nevertheless, some applications like Word 2010 or PSPad 4.5.6 interpret alt codes larger than 255 directly as a decimal Unicode codepoint.
To enable the third method, a user must set or create the registry key
HKCU\Control Panel\Input Method\EnableHexNumpad with type REG_SZ to value 1 and reboot (logging out and logging back in is sufficient). Once the registry key is set, the following method can be used to enter Unicode codepoints:
- Hold Alt and type the + key on the numeric keypad, then type the hexadecimal number (using the numeric keypad for digits 0-9 and the normal keys for a-f), then release Alt.
For example, Alt++11b will produce "ě" (e with caron).
The transition to Unicode actually made the older legacy Alt codes (the ones with no leading zero) more reliable, as all the glyphs in the legacy codepages 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. 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 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. Numeric entry of Unicode is done by the application or UI toolkit library has been somewhat standardized though there are slight variations. Sometimes all three of these work (for instance in Firefox):
- Hold Ctrl+⇧ Shift and type U followed by up to eight hex digits (on main keyboard or numpad). Then release Ctrl+⇧ Shift.
- Hold Ctrl+⇧ Shift+U and type up to eight hex digits, then release Ctrl+⇧ Shift+U.
- Type Ctrl+⇧ Shift+U, then type up to eight hex digits, then type ↵ Enter.
- Compose key for other operating systems
- Numeric character reference
- Unicode input
- Combining character