Skip to content

Commit bfbf2c4

Browse files
committed
Fix #1393: avoid dead key check for known unambiguous control characters
1 parent c48f77d commit bfbf2c4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

PSReadLine/Keys.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,21 @@ public override int GetHashCode()
115115
public static extern uint MapVirtualKey(ConsoleKey uCode, uint uMapType);
116116

117117
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
118-
public static extern int ToUnicode(
118+
public static extern int ToUnicodeEx(
119119
ConsoleKey uVirtKey,
120120
uint uScanCode,
121121
byte[] lpKeyState,
122122
[MarshalAs(UnmanagedType.LPArray)] [Out] char[] chars,
123123
int charMaxCount,
124-
uint flags);
124+
uint flags,
125+
IntPtr dwhkl);
126+
127+
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
128+
129+
private static extern IntPtr LoadKeyboardLayoutW(
130+
string pwszKLID,
131+
uint Flags
132+
);
125133

126134
static readonly ThreadLocal<char[]> toUnicodeBuffer = new ThreadLocal<char[]>(() => new char[2]);
127135
static readonly ThreadLocal<byte[]> toUnicodeStateBuffer = new ThreadLocal<byte[]>(() => new byte[256]);
@@ -147,7 +155,9 @@ internal static void TryGetCharFromConsoleKey(ConsoleKeyInfo key, ref char resul
147155
{
148156
flags |= (1 << 2); /* If bit 2 is set, keyboard state is not changed (Windows 10, version 1607 and newer) */
149157
}
150-
int charCount = ToUnicode(virtualKey, scanCode, state, chars, chars.Length, flags);
158+
159+
var kl = LoadKeyboardLayoutW("00000409", 0); // US English keyboard layout
160+
int charCount = ToUnicodeEx(virtualKey, scanCode, state, chars, chars.Length, flags, kl);
151161

152162
if (charCount == 1)
153163
{

0 commit comments

Comments
 (0)