Created
August 26, 2015 17:05
-
-
Save Markbnj/6ec69512af4690072f57 to your computer and use it in GitHub Desktop.
Get a single key press from the terminal in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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