Get a character from alt code (without keyboard ev

2019-07-26 16:47发布

问题:

I need to list all of the characters from alt codes. (If you somehow don't know what that is, hold down ALT and press one on the number pad, then repeat and hit 2, etc.) Is there a way to do this without using key events? What exactly I'm going to do is something like this;

for (int i = 0; i < 10; i++) {
    Console.Write(KeyCode(i)); //Obviously KeyCode() doesnt actually exist, thats what im asking for :P
}

I need this to work with Winforms and WPF if it matters, and Console would be nice to but I don't need it..

回答1:

According to Wikipedia, the 4-digit alt codes that begin with 0 correspond to the Windows-1252 character set, and the 3-digit codes correspond to DOS code page 437.



回答2:

i just realized you can do

char aaaa = (char)i;
//i is any alt code

is this the best/only way, and what encoding is this in?



标签: c# keyboard char