from msvcrt import getch
from threading import Thread
def catch_key():
while True:
n = getch()
Thread(target=main, args=(n,)).start()
if ord(n) == 27: # esc
break
def main(key):
print(f'{key} - {ord(key)}')
if __name__ == '__main__':
catch_key()