Created
November 10, 2016 13:03
-
-
Save antfu/5ad91b18dbbaced34e184867b8d28d11 to your computer and use it in GitHub Desktop.
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
# Portable "getch" | |
try: | |
from msvcrt import getch | |
except ImportError: | |
def getch(): | |
import sys, tty, termios | |
fd = sys.stdin.fileno() | |
old_settings = termios.tcgetattr(fd) | |
try: | |
tty.setraw(sys.stdin.fileno()) | |
ch = sys.stdin.read(1) | |
finally: | |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | |
return ch | |
def getunich(): | |
code = 0 | |
while True: | |
chcode = ord(getch()) | |
code *= 265 | |
code += chcode | |
if chcode != 224: | |
return code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment