I tried this
from msvcrt import getch
while True:
key = ord(getch())
if key == 27: #ESC
print("You pressed ESC")
elif key == 13: #Enter
print("You pressed key ENTER")
but it works only in terminal, i want to run a function whenever user presses the key, even his curser in not in terminal, Please help... Thank you!