How do I get a single keypress at a time?

For Windows, see:

how-do-i-check-for-a-keypress-without-blocking

For Unix variants: There are several solutions. It’s straightforward to do this using curses, but curses is a fairly large module to learn. Here’s a solution without curses:

import termios, fcntl, sys, os, select

fd = sys.stdin.fileno()

oldterm = termios.tcgetattr(fd)
newat