Skip to content

System.ConsoleKeyInfo can not handle Unicode surrogate pair and Emoji Sequences #27828

Description

@WenceyWang

Windows have a soft keyboard that can type Emoji directly.

image

Emoji is a set of chars that cannot be stored in a single char while System.ConsoleKeyInfo uses a char to store the content of the pressed key.

public char KeyChar { get; }

In my test, System.Console.ReadKey will return a System.ConsoleKeyInfo which KeyChar is the first char of the emoji (a sequence of surrogate pair, might 10+) and I have no way to get the other chars.

The problem of ReadKey is it may return the first half of a surrogate pair and the next ReadKey call will return the next keypress, not the remaining part of the surrogate pair.

This makes rubbish out and impossible to work around in user code.

This problem also applies to these keyboards for script language.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions