question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReadKey() functions misread arrow keys as ESC on 7.2.0 / Linux

See original GitHub issue

Prerequisites

Steps to reproduce

After upgrading from 7.1.5 to 7.2.0 on Linux, both $Host.UI.RawUI.ReadKey() and [Console]::ReadKey() functions return keycode 27 (ESC) when any of the arrow keys are pressed.

Expected behavior

$host.UI.RawUI.ReadKey()

VirtualKeyCode Character ControlKeyState KeyDown
-------------- --------- --------------- -------
            37                        0    True

When arrow key left is pressed; other arrows produce codes 38,39,40

Actual behavior

---clip---
$host.UI.RawUI.ReadKey()

VirtualKeyCode Character ControlKeyState KeyDown
-------------- --------- --------------- -------
            27                        0    True
---clap---
When any of the four arrow keys is pressed, result is always above.

Additionally, character 'A' is typed on next cmdline when up arrow is pressed, other arrows type chars C,B,D:

---clip---
PS > $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

VirtualKeyCode Character ControlKeyState KeyDown
-------------- --------- --------------- -------
            27         [0m               0    True

PS > A
---clap---
Pressing enter produces result as if I had typed the 'A' myself:

---clip---
A: The term 'A' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
---clap---

ReadKey() argument "NoEcho" has no effect on above behaviour.

Finally, the problem is not reproducible when running a powershell script from another shell. Executing script below from
either bash or zsh produces correct result, but executing from pwsh does not.

---clip---
#!/usr/bin/pwsh
$host.UI.RawUI.ReadKey()
---clap---

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Linux 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
daxian-dbwcommented, Sep 16, 2022

This was resolved in .NET 7-RC.1 release. The screenshot below is PowerShell built against .NET 7-RC.1 running on Ubuntu WSL2.

image

0reactions
daxian-dbwcommented, Sep 8, 2022

Opened https://github.com/dotnet/runtime/issues/75305 to ask for insights and clarification.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Read a keystroke from user
The module readchar tries to solve this problem by providing a function readkey which reads characters until is has read a complete key...
Read more >
Arrow keys, Home, End, tab-complete keys not working in ...
When I login on the new account, instead of the normal prompt I only see a $ sign. If I try to tab-complete...
Read more >
Console.ReadKey Method (System)
ReadKey(). Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window. ReadKey(Boolean).
Read more >
how to detect arrow key-press without pressing enter or ...
I want to be able to register wether or not a user clicked the up arrow to cycle through a command history like...
Read more >
BASH question: using read, can I capture a single char OR ...
My problem was that the escape keys I'd been monitoring were 3 ... Possible duplicate of bashscript to detect right arrow key being...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found