231 is the unicode prefix character. so your numeric keys are probably in a special mode (alt key on)
ConsoleKeyInfo.Key returns 231 for number keys 0..9
I have a program which uses the ReadKey function. The key property of the returned ConsoleKeyInfo structure is 231 for all the number keys 0..9 on the regular keyboard and the numeric key pad.
For the OnScreen keyboard the key returns 48..57.
The enum ConsoleKey (https://learn.microsoft.com/en-us/dotnet/api/system.consolekey?view=net-6.0) has values 48..57 (D0..D9) and 96..105 (NumPad0..NumPad9)
Is there a setting or an option to change this behaviour or is it a bug?
OS: Windows 10 Enterprise for Virtual Desktop
Version: 20H2
OS Build: 19042.1348
Keyboard: QWERTZ (Swiss German)
Language: Deutsch (Schweiz)
Region: de-CH
Small sample program:
static void Main(string[] args)
{
Console.WriteLine("Hello to Key Console");
Console.WriteLine("Press ESC to exit.");
bool exitProgram = false;
while (!exitProgram)
{
if (Console.KeyAvailable)
{
// https://learn.microsoft.com/en-us/dotnet/api/system.consolekeyinfo?view=net-6.0
var keyinfo = Console.ReadKey();
Console.WriteLine();
Console.WriteLine($"KeyChar: {keyinfo.KeyChar}");
Console.WriteLine($"Key: {(long)keyinfo.Key}");
Console.WriteLine($"Modifier: {(long)keyinfo.Modifiers}");
if (keyinfo.Key == ConsoleKey.Escape)
exitProgram = true;
}
}
}
Regular:
OnScreen: