This is the code I’m using
import time
import threading
import random
from pynput.mouse import Controller, Button
from pynput.keyboard import Listener, KeyCode
TOGGLE_KEY = KeyCode(char="1")
clicking = False
mouse = Controller()
#a=random.randint(176, 718)
#b=random.randint(732, 1215)
def clicker():
while True:
if clicking:
mouse.click(Button.right, 1)
for a in range(0, 10):
a=random.randint(732, 1215)
for b in range(0, 10):
b=random.randint(176, 500)
mouse.position=(a, b)
time.sleep(0.001)
def toggle_event(key):
if key == TOGGLE_KEY:
mouse.position = (759, 718)
global clicking
clicking = not clicking
click_threat = threading.Thread(target=clicker)
click_threat.start()
with Listener(on_press=toggle_event) as listener:
listener.join()
I tried different ways to add time with “if” but I didn’t succeed
I also tried with another time.sleep but the whole code thinks it should wait 12 seconds to execute and doesn’t do the clicks every 0.001 seconds.
New contributor
Andrés Jaramillo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.