How can I make Python do this task
from pynput.mouse import Button, Controller
mouse = Controller()
mouse.position(660,226)
mouse.press(Button.left)
mouse.release(Button.left)
every 10 seconds, X amount of times?
CodePudding user response:
You can wrap the thing you want to do multiple times in a for
block, for example like this:
for iteration in range(X):
# do the thing
Make sure to replace X by the amount of actions you want to do.
You can also add a time.sleep(seconds)
to the end of the action inside the for
block to make it sleep each time after completing the action.
CodePudding user response:
To make the task repeat, use a for loop. To do it every ten seconds, use the sleep function. Example:
from time import sleep
from pynput.mouse import Button, Controller
x = 10 # The amount of times to repeat the task
def task():
mouse = Controller()
mouse.position(660,226)
mouse.press(Button.left)
mouse.release(Button.left)
for _ in range(x):
task()
sleep(10)