Skip to content

Instantly share code, notes, and snippets.

@Markbnj Markbnj/getch.py
Created Aug 26, 2015

Embed
What would you like to do?
Get a single key press from the terminal in python
import termios
import sys
import tty
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
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
You can’t perform that action at this time.