def mainloop(keyfunc=None): change_termios() while True: while not kbhit(): continue key = getch() if isinstance(key, bytes) and bytes != str: key = key.decode() if key not in ascii_to_keycode: continue keycode = ascii_to_keycode[key] if keycode == "ESCAPE": break if keyfunc is not None: keyfunc(keycode) restore_termios()
import getch while True: if getch.kbhit(): key = ord(getch.getch()) print(key) if key == 27: break