Skip to content

@swdunlop /getch.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
def getch_unix( ):
old_settings = termios.tcgetattr( sys.stdin )
try:
tty.setraw( sys.stdin )
ch = sys.stdin.read( 1 )
finally:
termios.tcsetattr( sys.stdin, termios.TCSADRAIN, old_settings)
return ch
try:
import tty, sys, termios
getch = getch_unix
except ImportError:
import msvcrt
getch = getch_windows
def getch_win32( ):
return msvcrt.getch( )
@swdunlop
Owner

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

http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.