Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View getch.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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( )
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.