Created
March 13, 2017 16:37
-
-
Save rakesh-patnaik/442949af441766987223092ad6c51cb6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, fcntl, sys, os | |
fd = sys.stdin.fileno() | |
oldterm = termios.tcgetattr(fd) | |
newattr = termios.tcgetattr(fd) | |
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO | |
termios.tcsetattr(fd, termios.TCSANOW, newattr) | |
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) | |
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) | |
try: | |
while 1: | |
try: | |
c = sys.stdin.read(1) | |
print "You say {} but I say {}'.format(repr(c), repr(chr(ord(c) + 1))) | |
except IOError: pass | |
finally: | |
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) | |
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment