1import tty, sys, termios
2
3filedescriptors = termios.tcgetattr(sys.stdin)
4tty.setcbreak(sys.stdin)
5x = 0
6while 1:
7 x=sys.stdin.read(1)[0]
8 print("You pressed", x)
9 if x == "r":
10 print("If condition is met")
11termios.tcsetattr(sys.stdin, termios.TCSADRAIN,filedescriptors)