here is the output which is still running meaning it's not clicking: choose how many clicks you want the autoclicker to click at once>5 PRESS 's' TO START THE AUTOCLICKER AND 'q' TO QUIT. starting autoclicker... sqQUITING AUTOCLICKER starting autoclicker... and there was a error but it got cleared
import keyboard as kb
import pyautogui as pyg
def click(click):
if click == str:
click = int(input("Please enter a valid number: "))
elif click == int:
pyg.click(click) #this should make it click as many times I want //as much as the param is
clicks = int(input("choose how many clicks you want the autoclicker to click at once>"))
def start_autoclicker():
print("PRESS 's' TO START THE AUTOCLICKER AND 'q' TO QUIT.")
while True:
if kb.is_pressed("s"):
print("starting autoclicker...")
while True:
click(clicks)
if kb.is_pressed('q'):
print("QUITING AUTOCLICKER")
break
start_autoclicker()
First I was intending to make it ask how many times you want the autoclicker to click at once
then I defined that clicking part using pyautogui.click(clicks)
then I defined to start the autoclicking in a while loop if that makes since
here is the output which is still running meaning it's not clicking: choose how many clicks you want the autoclicker to click at once>5 PRESS 's' TO START THE AUTOCLICKER AND 'q' TO QUIT. starting autoclicker... sqQUITING AUTOCLICKER starting autoclicker... and there was a error but it got cleared
import keyboard as kb
import pyautogui as pyg
def click(click):
if click == str:
click = int(input("Please enter a valid number: "))
elif click == int:
pyg.click(click) #this should make it click as many times I want //as much as the param is
clicks = int(input("choose how many clicks you want the autoclicker to click at once>"))
def start_autoclicker():
print("PRESS 's' TO START THE AUTOCLICKER AND 'q' TO QUIT.")
while True:
if kb.is_pressed("s"):
print("starting autoclicker...")
while True:
click(clicks)
if kb.is_pressed('q'):
print("QUITING AUTOCLICKER")
break
start_autoclicker()
First I was intending to make it ask how many times you want the autoclicker to click at once
then I defined that clicking part using pyautogui.click(clicks)
then I defined to start the autoclicking in a while loop if that makes since
Share Improve this question edited Mar 15 at 8:42 Gino Mempin 29.8k31 gold badges119 silver badges166 bronze badges asked Mar 15 at 7:03 WixeperWixeper 11 silver badge2 Answers
Reset to default 1From PyAutoGUI documentation on Mouse Clicks
The click() function simulates a single, left-button mouse click at the mouse’s current position. A “click” is defined as pushing the button down and then releasing it up.
pyautogui.click()
does not click 'clicks' number of times when you pass an integer to it. Instead, it clicks once. To achieve multiple clicks, you need to use a loop.
import pyautogui as pyg
import time
def click(num_clicks):
for _ in range(num_clicks):
pyg.click()
time.sleep(0.01) # Add a small delay to avoid system overload
A small delay is added to prevent the clicks from happening too rapidly, which could overload the system or cause unexpected behavior. You can adjust the delay as needed.
This is all the code you asked for.
import keyboard as kb
import pyautogui as pyg
import time
def click(count):
"""Clicks the mouse n times."""
for _ in range(count):
pyg.click()
time.sleep(0.001) # Adds a small delay between clicks to avoid overwhelming the system
def get_valid_clicks():
"""Prompts the user to enter a valid number of clicks."""
while True:
try:
clicks = int(input("Choose how many clicks you want the autoclicker to click at once: "))
if clicks > 0:
return clicks
else:
print("Please enter a positive number.")
except ValueError:
print("Please enter a valid number.")
def start_autoclicker(clicks):
"""Starts the autoclicker when 's' is pressed and stops when 'q' is pressed."""
print("PRESS 's' TO START THE AUTOCLICKER AND 'q' TO QUIT.")
while True:
if kb.is_pressed("s"):
print("Starting autoclicker...")
while True:
click(clicks)
if kb.is_pressed('q'):
print("Stopping autoclicker...")
return # Exit the function to stop the autoclicker
if __name__ == "__main__": # This is optional (it runs it only when you run the file, not call it)
clicks = get_valid_clicks()
start_autoclicker(clicks)
# You can do this as well:
# clicks = get_valid_clicks()
# start_autoclicker(clicks)
# Without the 'if __name__ == "__main__":'
I hope I was helpful with the question.