Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does this script not stop but keeps spamming a and enter?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading