diff --git a/PSReadLine/Keys.cs b/PSReadLine/Keys.cs index 4a621bb2..73bf9cf5 100644 --- a/PSReadLine/Keys.cs +++ b/PSReadLine/Keys.cs @@ -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 toUnicodeBuffer = new ThreadLocal(() => new char[2]); static readonly ThreadLocal toUnicodeStateBuffer = new ThreadLocal(() => new byte[256]); @@ -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) {