Skip to content

[System.Console]::ReadKey() returns escape sequence characters when pressing arrow keys in PowerShell on Linux #75305

Closed
@daxian-dbw

Description

@daxian-dbw

Description

This is with PowerShell 7.3.0-preview.7, which runs on top of .NET 7-preview.7.

Running [System.Console]::ReadKey() in PowerShell, and then press UpArrow, it returns the escape sequences character by character -- Escape and then A.
It's the same to other arrow keys: DownArrow, LeftArrow, RightArrow

However, when using Console.ReadKey in an EXE built against .NET 7-preview.7, it returns UpArrow (and other arraow keys) as expected. Any ideas about what may cause this difference?

Related PowerShell issue: PowerShell/PowerShell#16443

Reproduction Steps

  1. Run PowerShell 7.3.0-preview.3, which runs on top of .NET 7-preview.7.
  2. Run [System.Console]::ReadKey()
  3. Press UpArrow

Expected behavior

[System.Console]::ReadKey() returns a ConsoleKeyInfo with those values: KeyChar: 0, Key: UpArrow, Modifier: 0

Actual behavior

[System.Console]::ReadKey() returns a ConsoleKeyInfo with the Escape key, and then a second ReadKey returns A

image

However, when using Console.ReadKey from an EXE that's built against .NET 7-preview.7, it works as expected:

image

Regression?

Not as far as I know. I observe the same behavior in .NET 6.

Known Workarounds

No response

Configuration

Which version of .NET is the code running on?
.NET 7-preview.7

What OS and version, and what distro if applicable?
Ubuntu 18.04

What is the architecture (x64, x86, ARM, ARM64)?
x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions