I have a while loop that iterates for 8 seconds, and inside it is a for loop which iterates 4 times, each time executing some pyautogui press functions. However, when my loop breaks, the for loop within continues until completion. Code:
import time
import pyautogui
timeout = time.time() + 8
while time.time() < timeout:
for i in range(4):
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("1")
pyautogui.press("4")
pyautogui.press("enter")
print(f"{time.time() - timeout } seconds more than while loop execute time")
Print statement output:
2.4774444103240967 seconds more than while loop execute time
So, how can I get my for loop to end with my while loop? I checked around on stack overflow but found nothing.
(used pyautogui.press("")
cause I got my error using them and they execute slower than print statements (can see the time difference better))