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

Marko Rauhamaa marko at pacujo.net
Wed Oct 26 00:44:35 EDT 2016


BartC <bc at freeuk.com>:
> And no one has the answered the question of how Curses or a GUI solves
> the problem of getting char or key events. Same machine, same OS, same
> keyboard, but one piece of software has apparently discovered the
> secret which is then denied to other software.

Curses, emacs, vi, bash, CPython, nethack etc "solve the problem" by
setting the terminal mode. You can, too:

    https://docs.python.org/3/library/termios.html
    https://docs.python.org/3/library/tty.html

However, that only gives you access to the interpreted characters. For
example, you can't see when a [Shift] key has been pressed.

> Some people want to work at low level, without needing to drag in a GUI,
> and want to do something as simple as finding out if a button has been
> pressed on a standard peripheral that nearly every computer has. It
> can't be that hard!

I don't consider that to be very low level. If you want to get to the
low level, open

   /dev/input/by-id/*-event-kbd

See:

   http://stackoverflow.com/questions/3662368/dev-input-keyboard-format


Marko



More information about the Python-list mailing list