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

Marko Rauhamaa marko at pacujo.net
Wed Oct 26 08:33:15 EDT 2016


BartC <bc at freeuk.com>:

> On 26/10/2016 05:44, Marko Rauhamaa wrote:
> (I've implemented 'keyboards' both on-screen, and on the surface of
> digitising tablets (also with a hacked Casio calculator pcb when I
> couldn't afford a real one). With all of those I was mainly interested
> in key events, not the details.)

Say you want to implement a simple, character-based shooting game where
the two guns are operated by the [Shift] keys. Unfortunately, the Unix
terminal API doesn't make that possible. You need to get the keyboard
events from some other API. In practice, your only choice is X11/Wayland
(on Linux).

> It's more building a mountain of complexity around something that
> ought to be straightforward.

Maybe there should be some way to get the raw events from the PTY.
However, next you'd start wanting the mouse events and pixel-level color
controls. It starts to look like a GUI application.

But what would be wrong in a GUI PTY API? No windowing, just a regular
character display where you could draw pictures and interpret the inputs
directly à la Apple II or Commodore 64.

It would make teaching programming much more fun, too.


Marko



More information about the Python-list mailing list