pls write me some python code that firsrt takes a mouse click from the user to get…
- User
pls write me some python code that firsrt takes a mouse click from the user to get screen co-ords and then performs 50 clicks with a random 1 to 3 second gap between clicks
- Assistant
In this code snippet, I will use the
pyautoguilibrary to handle mouse clicking and therandomlibrary to generate random intervals between the clicks.First, you will need to install the
pyautoguilibrary if you haven't already. You can do this by running the following command in your terminal:shellpip install pyautoguiHere's the code snippet:
pythonimport pyautogui import random import time def main(): print("Please click somewhere on the screen...") x, y = pyautogui.position() # Get the current position of the mouse for i in range(50): interval = random.randint(1, 3) # Generate a random interval between 1 and 3 seconds time.sleep(interval) # Wait for the interval pyautogui.click(x, y) # Click at the (x, y) position if __name__ == '__main__': main()