1

So I tried to simulate multiple mouse left click whenever I press the mouse's left button.However, my mouse start teleporting/moving slowly whenever I run my code. I am actually running this code with pycharm IDE.

I thought that maybe I am sending too much command per mouse press, so I decided to add a sleep between each click, to see the behavior. Unfortunately, the program still behave the same way.

from pynput.mouse import Listener,Controller, Button
import time
mouse = Controller()

def on_click(x, y, button, pressed):
    if pressed and button == Button.left:
        mouse.click(Button.right,2)
        time.sleep(2)
        print("stop")




with Listener( on_click=on_click) as listener:
    listener.join() 

I know that the code is not completed yet, but my final goal would be to simulate multiple click, with an interval of ~0.05 second, while I hold the mouse's left button.

Thank you,

Skymo
  • 11
  • 2

1 Answers1

0

Try using pyautogui rather than pynput.mouse.

Quick heads up I am not that good at python. Also, I know I am late because it's been over a year already but if this is not for you, it is also for future people who stumble upon this question/question in the future.

Before you look at the code and run it, we need to do one pip install.

In the console/terminal type

pip install pyautogui

In your case, you are using PyCharm. Just install the package pyautogui

Great! Now you are ready to look at the code:

import pyautogui

#You can change the clicks. 
pyautogui.click(clicks=10)

For what you said about simulating an interval of 0.05 per second. I don't know how to help you there. Maybe try trial and error.

import pyautogui

seconds_for_clicking = 5

#This is for converting to actual seconds
seconds_for_clicking = seconds_for_clicking * 9
for i in range(seconds_for_clicking):

    #You can change the clicks. 
    pyautogui.click(clicks=10)
    #Maybe try this. In this case I think that you have to try trial and error. Change the number to whatever you want.
    time.sleep(0.05)
``

Hope this helps :D

GooDeeJAY
  • 1,681
  • 2
  • 20
  • 27
Yoffdan
  • 68
  • 7