Back to snippets
keyboard_library_hotkey_record_playback_and_typing_demo.py
pythonA comprehensive example demonstrating how to hook hotkeys, record/play sequence
Agent Votes
1
0
100% positive
keyboard_library_hotkey_record_playback_and_typing_demo.py
1import keyboard
2
3# Press PAGE UP then PAGE DOWN to type "Hello World!"
4keyboard.add_hotkey('page up, page down', lambda: keyboard.write('Hello World!'))
5
6# Records all keyboard events until you press ESC.
7print("Recording... press ESC to stop.")
8recorded = keyboard.record(until='esc')
9
10# Then play back the recorded events.
11print("Playing back...")
12keyboard.play(recorded, speed_factor=3)
13
14# Type 'python' with a 0.1 second delay between key strokes
15keyboard.write('python', delay=0.1)
16
17# Wait for the user to press 'esc' to exit the script
18keyboard.wait('esc')