Why does this script not stop but keeps spamming a and enter?
import keyboard
import pyautogui
santtu = True
oliver = False
while santtu:
if keyboard.is_pressed("e"):
oliver = False
if keyboard.is_pressed("s"):
oliver = True
while oliver:
pyautogui.press("a", interval=1)
pyautogui.press("Enter", interval=1)
these were all the methods i tried:
if keyboard.is_pressed("e"):
global oliver
oliver = False
quit()
exit()
break
>Solution :
You are getting stuck in the while oliver loop. The program will remain in that loop until oliver is False. But given you change oliver to False outside the loop, it never becomes False again.
Try changing the while oliver to the below . This will cause the program to check the conditional, execute the code within it if oliver is True, then continue to the next iteration of the while santtu loop.
if oliver:
pyautogui.press("a", interval=1)
pyautogui.press("Enter", interval=1)