Skip to content

Commit

Permalink
Fix #1393: avoid dead key check for known unambiguous control characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jul 15, 2023
1 parent c48f77d commit bfbf2c4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions PSReadLine/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,21 @@ public override int GetHashCode()
public static extern uint MapVirtualKey(ConsoleKey uCode, uint uMapType);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int ToUnicode(
public static extern int ToUnicodeEx(
ConsoleKey uVirtKey,
uint uScanCode,
byte[] lpKeyState,
[MarshalAs(UnmanagedType.LPArray)] [Out] char[] chars,
int charMaxCount,
uint flags);
uint flags,
IntPtr dwhkl);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]

private static extern IntPtr LoadKeyboardLayoutW(
string pwszKLID,
uint Flags
);

static readonly ThreadLocal<char[]> toUnicodeBuffer = new ThreadLocal<char[]>(() => new char[2]);
static readonly ThreadLocal<byte[]> toUnicodeStateBuffer = new ThreadLocal<byte[]>(() => new byte[256]);
Expand All @@ -147,7 +155,9 @@ internal static void TryGetCharFromConsoleKey(ConsoleKeyInfo key, ref char resul
{
flags |= (1 << 2); /* If bit 2 is set, keyboard state is not changed (Windows 10, version 1607 and newer) */
}
int charCount = ToUnicode(virtualKey, scanCode, state, chars, chars.Length, flags);

var kl = LoadKeyboardLayoutW("00000409", 0); // US English keyboard layout
int charCount = ToUnicodeEx(virtualKey, scanCode, state, chars, chars.Length, flags, kl);

if (charCount == 1)
{
Expand Down

0 comments on commit bfbf2c4

Please sign in to comment.