Read keys persist there actions to the terminal
See original GitHub issue(This may be related to issue #22)
Relating to this StackOverflow post: Using keyboard module persists key actions to the terminal
It seems that when reading keys using read_key()
that (say for example a character key or the 'Enter'
key is read) the action for that key will persist in the terminal later if, say, the built-in input()
function is used.
E.g. Pressing the, say, q
key at an initial part of the program will later pre-populate input()
with the character q
when the user is next require to pass input. It would be nice if the read character from read_key()
did not get sent to stdin or stdout.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Using keyboard module persists key actions to the terminal
I have been able to temporarily resolve the issue by using the suppress=True keyword argument for the read_key() function.
Read more >Advanced Terminal Usage in Visual Studio Code
The terminal supports two different types of persistent sessions: ... Ensure the toggle sidebar visibility keybinding skips the shell "workbench.action.
Read more >Home and End keys not working - ArchWiki
A frequent problem in command line programs is that keys like Home and End do not work as expected. This is usually because...
Read more >Windows Terminal Actions | Microsoft Learn
Learn how to create custom actions for Windows Terminal. ... If the action does not have keys, it will appear in the command...
Read more >micro/keybindings.md at master · zyedidia/micro - GitHub
In iTerm2, you can do this in Preferences->Profiles->Keys then click the + , input your keybinding, and for the Action select Send Escape...
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 FreeTop 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
Top GitHub Comments
Yes, what you are looking for is “suppression” of events. Try
read_key(suppress=True)
, the event should not be populated in stdin.But please keep in mind that this library is meant for global events. So the character will be captured even if it was pressed when the terminal was not focused. If you want to just capture a single key without outputting it, something like
getch
is more appropriate. It’s a bit tricky to get working on Python, but there’s a module that solves it for you: https://pypi.org/project/getch/If it’s just backspace and enter, you are in luck, those actually count as characters and are returned by getch:
What you cannot get are modifiers, like alt, shift, caps-lock, etc, and F1-F12 keys (they just report 0x00).
Basically anything with its own ASCII code (and by extension present in Unicode), should work.