ReadKey() functions misread arrow keys as ESC on 7.2.0 / Linux
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This was resolved in .NET 7-RC.1 release. The screenshot below is PowerShell built against .NET 7-RC.1 running on Ubuntu WSL2.
Opened https://github.com/dotnet/runtime/issues/75305 to ask for insights and clarification.