I'm new to python and I'm trying to learn how to use the mouse and keyboard modules. I am trying to write some code that plays a recording while I'm holding left click, I think the issue is that this may be only part of the recording depending on how long I hold it. This is what I have so far but it isn't playing the recording.
import mouse
import keyboard
events = [] #This is the list where all the events will be stored
mouse.hook(events.append) #starting the recording
keyboard.wait("a") #Waiting for 'a' to be pressed
mouse.unhook(events.append) #Stopping the recording
def onleftclick():
while mouse.is_pressed(button='left') == True:
mouse.play(events)
mouse.on_click(onleftclick)
keyboard.wait('esc')
Use a keystroke to play back the recording. The recording won't play if you're using the mouse.
Try this code. Press
a
to play back the recording: