-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows Terminal] Console.KeyAvailable
causes the next Unicode character input 'EN DASH' to be skipped in console
#38966
Comments
Tagging subscribers to this area: @eiriktsarpalis |
Hi @daxian-dbw I tried your reproduction locally, but couldn't reproduce the issue. This is what I get on the powershell terminal: And this is what I see using powershell core on Windows terminal: This is using .NET Core 3.1.302, but the behaviour is similar in .NET 5 preview. |
@eiriktsarpalis Thanks for looking into this!
|
I'm still not reproducing :/ @daxian-dbw are you able to reproduce on a second machine? |
@eiriktsarpalis I found the OutputEncoding may plays a role here. I added using System;
using System.Text;
namespace console
{
public class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("OutputEncoding: {0}", Console.OutputEncoding.WebName);
Console.WriteLine("InputEncoding: {0}", Console.InputEncoding.WebName);
do {
if (Console.KeyAvailable)
{
var key = Console.ReadKey(true);
Print(key);
}
else
{
var key = Console.ReadKey(true);
Print(key);
}
}
while(true);
}
private static void Print(ConsoleKeyInfo key)
{
Console.Write('[');
Console.Write((int)key.KeyChar);
Console.Write($" {key.Key} {key.Modifiers}");
Console.Write(']');
}
}
} Run from cmd.exepaste "l –F" by right clicking:paste "–F" with the 'EN DASH' character being the first character by right clicking:Run from powershell corepaste "l –F" by right clicking:paste "–F" with the 'EN DASH' character being the first character by right clicking: |
@eiriktsarpalis Additional data point: I found this only reproduce in Windows Terminal. If I do the same in the conhost, then the 'EN DASH' character can always be captured as So a side question: why the 'EN DASH' character results in different |
I'm reproducing the same behaviour. Basically the character is omitted on Windows terminal only (reproducing with either cmd, PowerShell or Git Bash), but not on any other terminal emulators that I tested. It namely works for Visual Studio Console, Git bash, Powershell classic and ConEmu. I'll update the issue description accordingly. |
Console.KeyAvailable
causes the next Unicode character input 'EN DASH' to be skipped in consoleConsole.KeyAvailable
causes the next Unicode character input 'EN DASH' to be skipped in console
Also, the issue does not reproduce when using Windows terminal on WSL. |
This looks like a potential problem area. runtime/src/libraries/System.Console/src/System/ConsolePal.Windows.cs Lines 285 to 296 in d1c0fa8
Could it be possible that these characters are not triggering IsKeyDownEvent and this loop is eating them? |
I've noticed the same problem. Similarly, if you call
Oddly enough, it didn't happen in the Windows Terminal, but seemed to happen in the command prompt. Repro codeusing System;
namespace ConsoleApp28
{
class Program
{
static void Main(string[] args)
{
do
{
var keyInfo = Console.ReadKey(true);
Console.WriteLine($"KeyChar = {keyInfo.KeyChar}, Key = {keyInfo.Key}, Modifiers = {keyInfo.Modifiers}");
} while (Console.KeyAvailable/*true*/);
}
}
} Use
|
I've marked this issue with |
Description
When pasting text with Unicode character in it to console on Windows (conhost) using right click, the Unicode character, such as the 'EN DASH' character in the following example
will somehow be skipped and missing from the
Console.ReadKey(true)
calls. More investigation shows the call toConsole.KeyAvailable
could be the culprit -- whenConsole.KeyAvailable
is not in use,Console.ReadKey(true)
is able to receive the 'EN DASH' character just fine.Repro code
Copy the text "l –F", and then right click to paste the text, you will see that the 'EN DASH' character is missing:
Then, copy the text "–F" with the 'EN DASH' character being the first character, so
Console.KeyAvailable
will not run before accepting that character, thenConsole.Readkey(true)
is able to receive that Unicode character ():Additional information
Please note that, the same issue happens in .NET 5 preview as well.
If I change the
Main
method above to be the following, thenConsole.Readkey
can always receive the Unicode character.But I have to use
Console.KeyAvailable
in my project together withConsole.ReadKey
, and hence cannot receive the Unicode when user is pasting by right click in console.The text was updated successfully, but these errors were encountered: