#!/usr/bin/env python3 import sys, termios, tty, os, time def getch(): 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 while True: char = getch() if (char == "p"): print("Stop!") exit(0) if (char == "a"): print("Left pressed") time.sleep(1)