I want to create a function that records both mouse and keyboard events until a specific key is pressed and then replays them together.
I think that this can be achieved with the keyboard and mouse modules. In an earlier question, I asked how to record the mouse movement until a key is pressed, and I got the following code:
import mouse
import keyboard
events = [] #This is the list where all the events will be stored
mouse.hook(events.append) #starting the mouse recording
keyboard.wait("a") #Waiting for 'a' to be pressed
mouse.unhook(events.append) #Stopping the mouse recording
mouse.play(events) #Playing the recorded events
That works fine. As both modules were made by the same people, I assumed that the same would work with the keyboard module. But it doesn't.
mouse_events = []
keyboard_events = []
mouse.hook(mouse_events.append)
keyboard.hook(keyboard_events.append)
keyboard.wait("a")
mouse.unhook(events.append)
keyboard.unhook(events.append)
keyboard.play(events)
The keyboard.hook(events.append) line in the code above throws an error:
TypeError: unhashable type: 'list'.
I tried to check the module files but I fail to understand most of it.
So, to summarize: How can I start the mouse and keyboard recording at the same moment, stop them both at the same time and run both simultaneously? Are the mouse and keyboard modules the best option to achieve this?
