Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
def getch_unix( ):
old_settings = termios.tcgetattr( sys.stdin )
tty.setraw( sys.stdin )
ch = 1 )
termios.tcsetattr( sys.stdin, termios.TCSADRAIN, old_settings)
return ch
import tty, sys, termios
getch = getch_unix
except ImportError:
import msvcrt
getch = getch_windows
def getch_win32( ):
return msvcrt.getch( )

swdunlop commented Jul 19, 2010

Just a brutally simple way to capture a terminal keypress in Python. Derived from:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment