Why does using those two Alt codes in MS Word produce the same character?
Alt+0142
Alt+0381
This character: Ž
But in any other programs I tried so far (even MS Excel) the character }
gets produced when using this Alt code:
Alt+0381
ALT+0142 produces the character Ž
because 142 corresponds to this character in the Windows 1252 code page.
ALT+0381 also produces the character Ž
, because 381 is the decimal value of U+017D which correponds to this character in Unicode.
Alt codes with 4 digits starting with 0 produce the corresponding characters in the ANSI code page (Windows 1252, by default).
Alt codes with up to 3 digits not starting with 0 produce the corresponding characters in the OEM code page (Code page 437, by default).
All code pages have only 256 characters (0 to 255), so any alt code larger than 255 would produce the corresponding Unicode character in Word.
However, this does not apply to Excel, which simply computes the modulo 256 value and produces that character (in code page 437 or 1252, depending if it has 3 or 4 digits in OEM or ANSI code page, depending on the first digit). Note that 381-256=125, which corresponds to }
(in ASCII therefore in all code pages).
Alt+07
and see the bell in CP1252 rings instead of printing •
in CP437 despite the length isn't 4, and not even 3. 3) The decimal behavior for values larger than 255 is specific to Word. Most other apps including Excel and PowerPoint use the default Windows behavior where the value are always modulo 256. 4) Not all code pages have the lower 128 code points the same as ASCII, so therefore in all code pages
is wrong
The result of an Alt-code combination depends on both the foreground application and the first numpad key
Many applications have special treatment for Alt-code when they're in the foreground and receiving input. For example some apps simply take the first 3 digits and throw away the others. MS Word also captures the whole digit sequence but treats the whole decimal value as the Unicode code point without modulo. Wordpad also does the same. That's why Alt+0381 works in Word but not in most other apps. You don't even need the 0
prefix, just Alt+381 is enough
Word, Wordpad and other similar text editors like Libre Office also have an alternative which is typing the Unicode hexadecimal code point then press Alt+X, so try typing 17D
or U+17D
then Alt+X
However most other applications don't capture the Alt-code and use the default Windows behavior instead, in which the decimal values are always modulo 256 (i.e. only the least significant byte is taken), and when holding Alt the first numpad key defines the type of code page to use:
If it's numpad 1-9 then the DOS code page (A.K.A OEM code page) will be used
The default OEM code page on US Windows is CP437, so if you type Alt+144, Alt+400 or Alt+656... for example, then code point 144 in CP437 (which is U+00C9 É
if you check the CP437 table in the previous link) will be typed in, because 656 mod 256 = 400 mod 256 = 144
If it's numpad 0 then the Windows code page (A.K.A ANSI code page) will be used
By default the Windows code page is CP1252 on US Windows. So if you type Alt+0201, Alt+0457... then code point 201 in CP1252 will be typed in, which is also the same U+00C9 É
Similarly Alt+0142, Alt+0398, Alt+0654... all produce U+017D character Ž
which is code point 142 in CP1252, because 654 mode 256 = 398 mod 256 = 142
In the same vein Alt+0381 produces code point 381 mod 256 = 125 which is {
As a matter of fact Alt code originates from the DOS era, and people are so used to the Alt code in DOS that Microsoft can't break it when they use ANSI code pages in Windows and must differentiate the two with the 0
prefix
If it's numpad + then input is hexadecimal UCS2
Typing Alt++17D gives you the same Ž
character
Note that this requires the hexnumpad to be enabled by setting a REG_SZ
value with name EnableHexNumpad
in the HKCU\Control Panel\Input Method
registry key then reboot
See also
It looks like Word is interpreting ALT+0381 as Unicode U+017D, which is decimal representation 381
https://en.wikipedia.org/wiki/List_of_Unicode_characters shows:
U+017D Ž 381 Ž Latin Capital Letter Z with caron 0317
You get the same result by entering the Unicode character normally. First type:
017D
Then press Alt+x
Any character you can find on https://www.alt-codes.net/ is the same in Word and Notepad++. I don' think there IS an ASCII character 0381, I'm not sure why other programs interpret it as }
. The correct code would be alt+125 . Perhaps a smarter superuser can assist with that.