0

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?

martineau
  • 119,623
  • 25
  • 170
  • 301
Taylor
  • 11
  • 1

2 Answers2

1

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.

0x150
  • 589
  • 2
  • 11
0

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)
Nerd
  • 11
  • 1
  • 1