, , ConsoleKeyInfo PSReadline.
ConsoleKeyInfo PSConsoleReadLine, PSConsoleReadLine, ConsoleKeyInfo, . Nullable.
. JaredPar , ConsoleKey/ConsoleModifiers char. ( PSReadline ), , , PSReadline:
internal static char GetCharFromConsoleKey(ConsoleKey key, ConsoleModifiers modifiers)
{
char keyChar = '\u0000';
var state = new byte[256];
state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0);
state[NativeMethods.VK_CONTROL] = (byte)(((modifiers & ConsoleModifiers.Control) != 0) ? 0x80 : 0);
state[NativeMethods.VK_ALT] = (byte)(((modifiers & ConsoleModifiers.Alt) != 0) ? 0x80 : 0);
uint virtualKey = (uint)key;
uint scanCode = NativeMethods.MapVirtualKey(virtualKey, NativeMethods.MAPVK_VK_TO_VSC);
var chars = new char[2];
int charCount = NativeMethods.ToUnicode(
virtualKey, scanCode, state, chars, chars.Length, NativeMethods.MENU_IS_INACTIVE);
if (charCount == 1)
{
keyChar = chars[0];
}
return keyChar;
}