Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$Host.UI.RawUI.ReadKey Gets a extra enter key for no reason #291

Closed
avdaredevil opened this issue Oct 10, 2015 · 4 comments
Closed

$Host.UI.RawUI.ReadKey Gets a extra enter key for no reason #291

avdaredevil opened this issue Oct 10, 2015 · 4 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.

Comments

@avdaredevil
Copy link

A lot of my powershell apps rely on

$Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho");

to get input, since I do simultaneous thread/non-thread activities, while the user takes time writing his/her input.

Problem is that with PSReadLine the first Prompt after a script is executed already receives an "enter" thus it treats it as if the user wanted to skip the input. This however does not affect

[Console]::ReadKey()

Please advise.

@lzybkr
Copy link
Member

lzybkr commented Oct 13, 2015

Try using IncludeKeyDown instead of IncludeKeyUp.

PSReadline calls Console.ReadKey, which ignores KeyUp events, and returns when it sees a KeyDown event. So after you press Enter (KeyDown), Console.ReadKey (and hence PSReadline) does not consume the KeyUp event.

@avdaredevil
Copy link
Author

The problem with that approach is that if the user holds the key for too long, there are redundant keys typed, when I would like only one per key press. The fallback I currently use is adding an extra $Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho"); when I detect PSReadLine. This way the first "ghost-enter" gets consumed, and the apps behave normally.

@lzybkr lzybkr added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Nov 8, 2017
@lzybkr
Copy link
Member

lzybkr commented Nov 8, 2017

It seems reasonable for PSReadLine to consume the final KeyUp before returning to the caller.

@daxian-dbw
Copy link
Member

Close as a duplicate of #959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

No branches or pull requests

3 participants