-
Notifications
You must be signed in to change notification settings - Fork 46
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
feature request - non-blocking / timeout #62
Comments
I implemented the non-blocking version in #79 |
Excellent. Thanks a lot! |
we will see when magmax comes back and merges it 😃 |
So, turns out stuff is more complex on the linux side... Which is why I removed this feature form the v4 development for now. When working on linux systems, we need to reconfigure the terminal to fit readchars needs (don't echo pressed keys back to the user, don't stop on The easiest soloution is probably to use multiple threads and have To get this behavior working on a single thread the user would have to first set up the Terminal, then run his code and then runs some more code to reset the terminal. This would call for a context-manager and is defnetly possible, but making it libary read is difficult and it would add much more complexety when using the libary. Here is a example of how it could look: with KeyReader() as r:
spinner = cycle(["-", "/", "|", "\\"])
while True:
print("\rpress a key: " + next(spinner), end="")
if r.kbhit():
k = r.readkey()
print(f"\r{k.encode()}-key was pressed")
# do other stuff would this be of use to you if it was part of the libary? |
Is there a way to have a non-blocking version that returns
None
or raises an exception if there no current key?Or, even better, to have a timeout, and then do the above after the timeout has passed and no key was pressed or no character entered, respectively?
The text was updated successfully, but these errors were encountered: