I have a program that starts a loop. Whenever I press, for example, the βESCβ key on the keyboard, it should call a function that prints βYou pressed the ESC keyβ and possibly executes some commands.
I tried this:
from msvcrt import getch while True: key = ord(getch()) if key == 27:
After all my attempts, msvcrt does not seem to work in python 3.3 or for any other reason. Basically, how can I make my program respond to any keystroke at any given time while the program is running?
EDIT: Also, I found this:
import sys while True: char = sys.stdin.read(1) print ("You pressed: "+char) char = sys.stdin.read(1)
But to enter the input file, I need to enter the input into the console, but I have my loop running in tkinter, so I still need it to do something right after it detects a keypress.
source share