1
from playsound import playsound
from pynput import mouse

def on_click(x, y, button, pressed):
    if pressed: 
        print("clicked")
        playsound("clicking.wav")                                                   
    
    if not pressed:
        # Stop listener
        print("unclicked")
        return False
    
while True:
    with mouse.Listener(on_click=on_click,) as listener:
        listener.join()

Point of this program is to simulate the sound of clicking really fast. However when I run the sound file of fast clicking (clicking.wav) my mouse becomes very laggy and the program doesn't listen for when I'm not holding down right click, it keeps playing the sound file regardless. I am very unsure of how to fix this.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
chids
  • 25
  • 4

1 Answers1

1

You must set the block parameter to False:

playsound('sound.mp3', block=False)
tomas
  • 13
  • 3