So I've been trying to make a simple program that, upon clicking the right mouse button, makes my mouse click the left button 3 times in 0.5 second intervals. However, when I start the program and do right click, the program does what it's told to do but also starts lagging horrendously for about 25 seconds. After it's done lagging and I try to close the program, it freezes, forcing me to close it via task manager.
The code is as follows:
import time
from pynput.mouse import Button, Controller, Listener
mouse = Controller()
def on_click(x, y, button, pressed):
    if button == Button.right:
        num = 3
        while num > 0:
            time.sleep(0.5)
            mouse.click(Button.left)
            num -= 1
with Listener(on_click=on_click) as listener:
    listener.join()
Any help is greatly appreciated.
After some time debugging and digging though issues, it seems that pynput.mouse.Listener has a few problems hanging/lagging on Windows machines when moving the mouse.
On a Linux machine, things should work fine out of the box with no hanging or lagging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With