Home > Blockchain >  Python Looping Script
Python Looping Script

Time:08-13

I am fairly new to Python and attempting to create a script that automates a task for me. I am unable to figure out how to make the script loop at the start after completing the last sleep. How do I make the script repeat endlessly? I've been testing around with while loops to create a true statement.

from pyautogui import *
import pyautogui
import time
import keyboard
import numpy as np
import random
import win32api, win32con

time.sleep(5)

def click(x,y):
    time.sleep(0.1) #This pasues the script for 0.01 seconds
    win32api.SetCursorPos((x,y))
    time.sleep(0.1) #This pasues the script for 0.01 seconds
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(0.1) #This pasues the script for 0.01 seconds
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

#Selecting play
click(347,323)

#Wait
time.sleep(1)

#Selecting server
click(263,465)

#Wait for loading screen
time.sleep(45)

#Interact with NPC /// E   space, arrow key down   space, tab, esc, z,
pyautogui.keyDown('e')
time.sleep(0.1)
pyautogui.keyUp('e')

time.sleep(1)

pyautogui.keyDown('space')
time.sleep(0.1)
pyautogui.keyUp('space')

time.sleep(1)

click(532,701)

time.sleep(1)

pyautogui.keyDown('tab')
time.sleep(0.1)
pyautogui.keyUp('tab')

time.sleep(1)

pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')

time.sleep(1)

pyautogui.keyDown('z')
time.sleep(0.1)
pyautogui.keyUp('z')

time.sleep(1)

click(218,730)

time.sleep(1)

pyautogui.keyDown('space')
time.sleep(0.1)
pyautogui.keyUp('space')

time.sleep(10)

CodePudding user response:

while True:
    # do some things over here
    time.sleep(some delay)

CodePudding user response:

Why would throwing your code into a permanent while loop not be enough?

from pyautogui import *
import pyautogui
import time
import keyboard
import numpy as np
import random
import win32api, win32con

time.sleep(5)

def click(x,y):
    time.sleep(0.1) #This pasues the script for 0.01 seconds
    win32api.SetCursorPos((x,y))
    time.sleep(0.1) #This pasues the script for 0.01 seconds
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(0.1) #This pasues the script for 0.01 seconds
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

while True:
    #Selecting play
    click(347,323)

    #Wait
    time.sleep(1)

    #Selecting server
    click(263,465)

    #Wait for loading screen
    time.sleep(45)

    #Interact with NPC /// E   space, arrow key down   space, tab, esc, z,
    pyautogui.keyDown('e')
    time.sleep(0.1)
    pyautogui.keyUp('e')

    time.sleep(1)

    pyautogui.keyDown('space')
    time.sleep(0.1)
    pyautogui.keyUp('space')

    time.sleep(1)

    click(532,701)

    time.sleep(1)

    pyautogui.keyDown('tab')
    time.sleep(0.1)
    pyautogui.keyUp('tab')

    time.sleep(1)

    pyautogui.keyDown('esc')
    time.sleep(0.1)
    pyautogui.keyUp('esc')

    time.sleep(1)

    pyautogui.keyDown('z')
    time.sleep(0.1)
    pyautogui.keyUp('z')

    time.sleep(1)

    click(218,730)

    time.sleep(1)

    pyautogui.keyDown('space')
    time.sleep(0.1)
    pyautogui.keyUp('space')

    time.sleep(10)
  • Related