1import keyboard # using module keyboard
2while True: # making a loop
3 try: # used try so that if user pressed other than the given key error will not be shown
4 if keyboard.is_pressed('q'): # if key 'q' is pressed
5 print('You Pressed A Key!')
6 break # finishing the loop
7 except:
8 break # if user pressed a key other than the given key the loop will break