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
Let System.ConsoleKeyInfo able to represent keypress in the Unicode world #51085
These problems can be easily fixed by adding a new property.
Proposed API
namespace System
{
public struct ConsoleKeyInfo {
+ public ReadOnlySpan<System.Text.Rune> KeyCharacters { get; }
}
Usage Examples
StringBuilderinputText=newStringBuilder();while(true){ConsoleKeyInfokey=Console.ReadKey(true);switch(key.Key){caseConsoleKey.Escape:caseConsoleKey.Enter:// Some Logicbreak;default:foreach(Runeruneinkey.KeyCharacters){inputText.Append(rune);}break;}}
Alternative Designs
The property type can also be ReadOnlySpan<char> or even string. The name can also be different.
For reference, there's a discussion going on at #27828 on whether a string-returning API needs to be added, or whether callers can keep querying the KeyChar property over and over in a loop, stitching together the key presses and building up the input string.
Activity
GrabYourPitchforks commentedon Apr 13, 2021
For reference, there's a discussion going on at #27828 on whether a
string-returning API needs to be added, or whether callers can keep querying the KeyChar property over and over in a loop, stitching together the key presses and building up the input string.adamsitnik commentedon Nov 13, 2023
Closing as a duplicate of #27828