[Python] Pause loop to make a certain action then continue where you left off inside of it

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    import pyautogui
    import time


    def RunD(Down, Up): #Up is the parameter that creates the delay
    pyautogui.keyDown('d')
    pyautogui.mouseDown(button='left')
    time.sleep(Down)
    pyautogui.keyUp('d')
    pyautogui.mouseUp(button='left')
    time.sleep(Up)

    buff() #should be called every 30s

    for i in range(15):
    RunA(34.5,0)
    Advance(1,0)
    EnterD(0.2,0)
    RunD(34.5,0)
    Advance(1,0)
    EnterA(0.2,0)


    This is basically a script that allows me to automate a simple yet tedius task. All of the following functions have the same structure as the defined one, the only difference being that there are different keys at work.
    I need to "pause" this program for .1s each 30s so that I can execute another function, speedUp, then go back where I left off in the loop. The problem is that when exiting the loop to execute said function I do not know how to continue having the keys pressed where I left off and for the remaining time that I gave it.

    I do not know how to proceed and I am very lost

    Continue reading...

Compartilhe esta Página