Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I want to design an automatic-clicker that will take the place of your mouse, and clicks in that position as long as "active" is true and at "input" 's speed (clicks per second)

I have used the below code but it is not giving me the desired output:

import win32api, win32con

def click(x,y):

    win32api.SetCursorPos((x,y))

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

click(10,10)

I want the code to look like this:

import library 

input = 5 ## in clicks per second

if (some key) is held:

    active = True

if (some key) is released:

    active = False

while active:

     *gets the position of mouse*

     *clicks at that position at input's speed (5)

1 Answer

0 votes
by (108k points)

Try using pyautogui. I have used this in several projects. It has huge functionalities with less coding. For instance, if you want to click on the middle of the screen, simply do:

import pyautogui

width, height = pyautogui.size()

pyautogui.click(width/2, height/2)

In your case, you may use the time module to synchronize the actions.

For more information regarding the same, do refer to the Python tutorial that will help you out in a better way.

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
1 answer
asked Jul 29, 2019 in Python by Rajesh Malhotra (19.9k points)

Browse Categories

...