Skip to content

Instantly share code, notes, and snippets.

@EdwardBetts
Created June 27, 2017 18:59
Show Gist options
  • Save EdwardBetts/b4328d6ce0240059cb649954b1f2803c to your computer and use it in GitHub Desktop.
Save EdwardBetts/b4328d6ce0240059cb649954b1f2803c to your computer and use it in GitHub Desktop.
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
except KeyboardInterrupt:
raise
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment