pip install keyboard import keyboard while True: # do something if keyboard.is_pressed("q"): print("q pressed, ending loop") break
if exp.response == 'space': breaking_variable = False