You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ctrl-C doesn't work if PowerShell was started with Russian keyboard layout #1393
Enable Russian keyboard layout on Windows (I use Alt-Shift to do that)
Start PowerShell Core 7.0 (which includes PSReadLine 2.0)
Press Ctrl-C in the shell
Expected behavior
Ctrl-C should terminate current command/input/whatever, it should work as Ctrl-C usually do.
Actual behavior
Russian letter "с" getting inserted into the command line, and no actual Ctrl-C behavior happens.
Ctrl-C is still broken even if I switch to the English keyboard layout (then English letter "c" gets inserted inctead of actual Ctrl-C behavior heppening).
Reacted by Sublihim, Ivan, Oleksii Sachek, Ilya Borisov, 0x241F31, ili101, Dan Kov, Vladimir Zagray, Mordechai Alter, SeryiBaran and 6 more
Ilya (@iSazonov), no, I cannot reproduce the issue without PSReadLine.
Isn't this repository already a PSReadLine repo? I can see that some repository movement has been involved, but this is definitely a repo I have been reporting PSReadLine issues earlier.
Please direct me to a right repo if this isn't right. I've tried searching for other PSReadLine repo but wasn't successful, sorry.
Ctrl-C is still broken even if I switch to the English keyboard layout (then English letter "c" gets inserted inctead of actual Ctrl-C behavior heppening).
Friedrich von Never (@ForNeVeR) Thanks for the reporting. Just want some clarification on this behavior, was it broken for you when using the English keyboard from the very beginning?
Start PSReadline (e.g. by starting PSReadline-net461 from sources).
Enable Russian keyboard layout, and then press Ctrl-C or Ctrl-R one time (it won't work).
After that, you may change the current keyboard layout as many times as you want, Ctrl-hotkeys won't work for you in this session. The session is absolutely broken.
Also, I've been able to reproduce the issue both in PowerShell Core and in PowerShell 5.1.
I was able to determine that the culprit is likely Microsoft.PowerShell.PSKeyInfo.KeyInfoAsString: this method returns a string "Ctrl+к" even when I press Ctrl-r with English keyboard layout enabled (and the input argument properly indicates Ctrl+r as being pressed). Most likely, there're two different issues:
Something in PSKeyInfo is static and wrongly so, so it remembers my (Russian) keyboard layout when I enter this method for the first time, and then reuses this layout even if I change it afterwards.
It just doesn't work as it should: it relies on the current keyboard layout for some reason, when the expected behavior would be to ignore it and always use the default one (at least, every single program I know behaves that way with the Russian+English keyboard layouts; there may be some exceptions from this rule, but I'm not aware of them yet).
On my system, it looks like it remembers the first keyboard layout with which it is called, and then it just uses it for all subsequent calls. So, while it obviously should hold "r" for input values of ConsoleKey.R, 19, (an array of 256 zeros), (an array of 2 zeros), 2, 4, actually it returns a Russian letter "к".
In the documentation, it isn't specified which layout it will use, but I could try to guess it uses current thread layout or something like that, and, since this code is called on a background thread (which may not process keyboard layout change messages properly), it may actually auto-initialize the keyboard layout for the first usage, and then leave it as-is. And this behavior could be dependent on OS version, installed language pack, or whatever else factor comes into play here.
I believe we could try to load an English keyboard layout and pass it to ToUnicodeEx (which takes a layout as input instead of relying on some vague global value), since our hotkeys seem to be specified in English.
Jason Shirk (@lzybkr), am I right? Would that be a good fix for the issue? I'm not quite sure why do you call all this ToUnicode business instead of e.g. creating a table like ConsoleKey.R => "r", but it surely was a good reason, I presume?
Console applications are "sticky" with regards to the keyboard layout. I reported this as a bug to the appropriate internal team but there were concerns of appcompat issues.
I don't know if specifying the English keyboard layout works correctly or not. Hopefully it would, but I vaguely recall experimenting specifying an explicit keyboard layout and it not working.
That said, I don't know under what conditions you would specify the English keyboard layout. How would PSReadLine know, for any given keyboard layout, that you really wanted a shortcut given that some normal keys use modifiers to type. This is why PSReadLine uses ToUnicode in the first place.
Folks, love y'all so much. Finally, we'll have a significant improvement on this in the next release ❤️
The shortcuts are still expected to be defunct if you have a "wrong" keyboard layout enabled when you hit Ctrl+C, but it won't stick with you until the end of PowerShell session: just change the layout to English, and it will start working again.
It was verified in several terminal apps (including the Windows Terminal, of course), but there are cases when it is still broken (e.g. in the old console, or when you start Windows Terminal as a default terminal app, as opposed to explicitly clicking the Terminal icon).
I'd suggest to report new cases separately, and you may link them in this thread. I'll try to take a look at new particular scenarios and improve them if possible.
But again: we expect that in majority of cases, the issue will be gone next release. I am so happy 🎉
Reacted by karb0f0s, SeryiBaran and Denis Bendrikov
I've just ran in to this, and this still seems to be a problem.
If you start PowerShell (7.4.1), with a Russian layout enabled. CTRL+C wouldn't be working. Switching back to Eng layout doesn't fix the issue. More, if you hold CTRL and press any button, the letters will be in a layout you started with, regardless of if you switched layouts or not. I.e. switch to Eng, press F button see F on screen, hold CTRL press F, see A(Ru) on screen.
Activity
iSazonov commentedon Mar 7, 2020
Friedrich von Never (@ForNeVeR) Do you see the issue without PSReadline? If no please move the issue to PSReadline repo.
ForNeVeR commentedon Mar 8, 2020
Ilya (@iSazonov), no, I cannot reproduce the issue without PSReadLine.
Isn't this repository already a PSReadLine repo? I can see that some repository movement has been involved, but this is definitely a repo I have been reporting PSReadLine issues earlier.
Please direct me to a right repo if this isn't right. I've tried searching for other PSReadLine repo but wasn't successful, sorry.
iSazonov commentedon Mar 8, 2020
Oh, sorry.
daxian-dbw commentedon Mar 18, 2020
Friedrich von Never (@ForNeVeR) Thanks for the reporting. Just want some clarification on this behavior, was it broken for you when using the English keyboard from the very beginning?
ForNeVeR commentedon Mar 19, 2020
Ctrl-C works fine if I start PowerShell session when English keyboard layout is active. It is only broken if I start the session with Russian layout.
daxian-dbw commentedon Apr 2, 2020
A duplicate of this issue is reported in #1442 with a different repro --
ctrl+rresults in the Russian letter к.ForNeVeR commentedon Apr 2, 2020
Yes, actually all of the Ctrl-hotkeys are broken.
ForNeVeR commentedon Aug 23, 2020
Exact steps to reproduce:
PSReadline-net461from sources).Also, I've been able to reproduce the issue both in PowerShell Core and in PowerShell 5.1.
I was able to determine that the culprit is likely
Microsoft.PowerShell.PSKeyInfo.KeyInfoAsString: this method returns a string"Ctrl+к"even when I pressCtrl-rwith English keyboard layout enabled (and the input argument properly indicatesCtrl+ras being pressed). Most likely, there're two different issues:PSKeyInfois static and wrongly so, so it remembers my (Russian) keyboard layout when I enter this method for the first time, and then reuses this layout even if I change it afterwards.I'll try to investigate further.
ForNeVeR commentedon Aug 24, 2020
This call of
ToUnicodecauses problems:PSReadLine/PSReadLine/Keys.cs
Line 150 in 7024968
On my system, it looks like it remembers the first keyboard layout with which it is called, and then it just uses it for all subsequent calls. So, while it obviously should hold
"r"for input values ofConsoleKey.R, 19, (an array of 256 zeros), (an array of 2 zeros), 2, 4, actually it returns a Russian letter"к".In the documentation, it isn't specified which layout it will use, but I could try to guess it uses current thread layout or something like that, and, since this code is called on a background thread (which may not process keyboard layout change messages properly), it may actually auto-initialize the keyboard layout for the first usage, and then leave it as-is. And this behavior could be dependent on OS version, installed language pack, or whatever else factor comes into play here.
I believe we could try to load an English keyboard layout and pass it to
ToUnicodeEx(which takes a layout as input instead of relying on some vague global value), since our hotkeys seem to be specified in English.Jason Shirk (@lzybkr), am I right? Would that be a good fix for the issue? I'm not quite sure why do you call all this
ToUnicodebusiness instead of e.g. creating a table likeConsoleKey.R => "r", but it surely was a good reason, I presume?lzybkr commentedon Aug 24, 2020
Console applications are "sticky" with regards to the keyboard layout. I reported this as a bug to the appropriate internal team but there were concerns of appcompat issues.
I don't know if specifying the English keyboard layout works correctly or not. Hopefully it would, but I vaguely recall experimenting specifying an explicit keyboard layout and it not working.
That said, I don't know under what conditions you would specify the English keyboard layout. How would PSReadLine know, for any given keyboard layout, that you really wanted a shortcut given that some normal keys use modifiers to type. This is why PSReadLine uses
ToUnicodein the first place.44 remaining items
Fix PowerShell#1393: avoid dead key check for known unambiguous contr…
(PowerShell#1393) Windows keyboard layout: determine parent terminal …
(PowerShell#1393) Address the PR feedback
(PowerShell#1393) Address the PR feedback
(PowerShell#1393) Windows keyboard layouts: introduce the process tre…
(PowerShell#1393) Address the PR feedback
ForNeVeR commentedon Nov 3, 2023
Folks, love y'all so much. Finally, we'll have a significant improvement on this in the next release ❤️
The shortcuts are still expected to be defunct if you have a "wrong" keyboard layout enabled when you hit
Ctrl+C, but it won't stick with you until the end of PowerShell session: just change the layout to English, and it will start working again.It was verified in several terminal apps (including the Windows Terminal, of course), but there are cases when it is still broken (e.g. in the old console, or when you start Windows Terminal as a default terminal app, as opposed to explicitly clicking the Terminal icon).
I'd suggest to report new cases separately, and you may link them in this thread. I'll try to take a look at new particular scenarios and improve them if possible.
But again: we expect that in majority of cases, the issue will be gone next release. I am so happy 🎉
TimofeyBiryukov commentedon Feb 7, 2024
I've just ran in to this, and this still seems to be a problem.
If you start PowerShell (7.4.1), with a Russian layout enabled. CTRL+C wouldn't be working. Switching back to Eng layout doesn't fix the issue. More, if you hold CTRL and press any button, the letters will be in a layout you started with, regardless of if you switched layouts or not. I.e. switch to Eng, press F button see F on screen, hold CTRL press F, see A(Ru) on screen.
ForNeVeR commentedon Feb 7, 2024
Not sure if the fix was integrated into 7.4.1. So far, it looks like the latest release of PSReadLine is 2.3.4, built before merging of my PR.
So, it looks like we just need to wait for a bit more for the next release.
In the meantime, I think you can use my workaround fork (installation instructions are notably messy but are included in the release page).
Kadeluxe commentedon Apr 18, 2024
I'm on 7.4.2 and it's not working without manually replacing.
ForNeVeR commentedon Apr 18, 2024
Sadly, the last release, PSReadLine v2.3.5, still doesn't have my fix included. Check the list of commits by this link: v2.3.5...master
daxian-dbw commentedon Apr 18, 2024
The fix is included in v2.4.0-beta0. Please install that version and try again.
Kadeluxe commentedon Apr 18, 2024
Install-Module -Name PSReadLine -AllowPrerelease -Forceworked, thanks for the tip.Once again Friedrich von Never (@ForNeVeR) thank you for your time, I really do appreciate your work here.
bn45hkurr0y4 commentedon Jan 29, 2026
This problem still exists in PSReadline 2.4.5.
bash/zsh/cmd do not have this problem.