Why doesn't Python include non-blocking keyboard input function?

Paul Rubin no.email at nospam.invalid
Tue Oct 25 12:32:29 EDT 2016


jladasky at itu.edu writes:
> ... I find myself asking why Python doesn't include a standard,
> non-blocking keyboard input function.  I have often wanted one myself.

I agree this would be useful.  Forth has a standard word KEY to read a
key, and I used it in a simple game that I wrote a few months ago
(you enter a key indicating which way you want to move).  

> The only way that I've ever achieved this behavior is: ...

In *nix you should be able to set the tty modes with fcntl.ioctl so that
reading from stdin returns immediately when you hit a key.  You should
be able to use select.select with zero timeout to see whether input is
available.



More information about the Python-list mailing list