Skip to content

System.Console.ReadKey is lame on Windows; brilliant on Linux #96490

@tig

Description

@tig

Description

Terminal.Gui uses System.Console for its "least-common-denominator" console driver (NetDriver).

We call System.Console.ReadKey to process keyboard input.

We've noticed that the key info we get on Windows vs Linux is wildy different. Prior to dotnet7, both behaved the same (badly).

With dotnet7 & 8 Linux is WAY better.

For example, if the user presses "Ctrl+7", on Linux we get the right key info. On Windows we get [ConsoleKeyInfo(Key: Null (None), KeyChar: ␟ (31))].

For "Ctrl+7" we get [ConsoleKeyInfo(Key: Space, W (F8) | Control, KeyChar: ␀ (0))]

For reference, "Ctrl+A" works fine: [ConsoleKeyInfo(Key: A (A) | Control, KeyChar: a (65))]

Is there something we can do to make Windows work as well as Linux (what a strange thing to ask :-))?

Reproduction Steps

Using the v2_develop branch of Terminal.Gui debug the UI Catalog -usc in the VS debugger. This runs UI Catalog using the NetDriver.

Open the Keys scenario and press "Ctrl+7" (you might need to unbind that key from WT's actions).

Note garbage.
image

Now run the WSL: UI Catalog -usc debug profile. This runs UI Catalog in WSL using NetDriver.

Open Keys and press "Ctrl+7". You'll see this:
image

Expected behavior

image

Actual behavior

image

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions