Created
April 11, 2016 11:11
-
-
Save glaslos/600a112c4db8b2560c6029169f96a05c 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
import sys | |
import tty | |
import termios | |
fd = sys.stdin.fileno() | |
# keep original terminal settings | |
old_settings = termios.tcgetattr(fd) | |
def readone(): | |
try: | |
# set terminal to raw | |
tty.setraw(sys.stdin.fileno()) | |
ch = sys.stdin.read(1) | |
except Exception as e: | |
print(e) | |
finally: | |
# resetting terminal for printing | |
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) | |
return ch | |
while True: | |
ch = readone() | |
chk = ord(ch) | |
if chk in [3, 4]: | |
# ctrl+c and ctrl+d | |
break | |
print(repr(ch)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment