magmax / python-readchar

Python library to read characters and key strokes
MIT License
143 stars 43 forks source link

Don't drop Keypresses outside of readchar_linux() #74

Closed vanschelven closed 2 years ago

vanschelven commented 2 years ago

Calling tty.setraw makes it so that subsequent calls to read() don't read any of the typed-but-not-read characters. Reading the code, this could be expected since tty.setraw is called without explicit parameters, and the default for when is TCSAFLUSH, which means:

If optional_actions is TCSAFLUSH, the change shall occur after all output written to fildes is transmitted, and all input so far received but not read shall be discarded before the change is made. (emphasis mine)

Indeed, changing the call to be with TCSADRAIN seems to solve the problem of missing keystrokes.

However, that solves the problem that any keystrokes that occur outside of readchar are dropped fully, but it does not solve the problem that they will be echoed. (They will be echoed because they occur at a point in time that stdin is in "cooked" or "canonical" (non-raw) mode).

See #73

Cube707 commented 2 years ago

Hello,

I am working on similar problem over on https://github.com/Cube707/python-readchar/pull/5 and as my experiences with the unix-termianl are limited, your insigt might be helpfull. If you can find the time you may want to take a look.

Cube707 commented 2 years ago

this PR is no longer relevant in v4.0.0 but discussion on how to deal with this problem continues in the original issue