python stop loop on keypress code example
Example 1: python press key to break
if keyboard.is_pressed('q'): # if key 'q' is pressed
print('You Pressed A Key!')
break # finishing the loop
Example 2: python loop break on keypress
try:
while True:
do_something()
except KeyboardInterrupt:
pass