def play(events, speed_factor=<NUM_LIT:1.0>):
state = stash_state()<EOL>last_time = None<EOL>for event in events:<EOL><INDENT>if speed_factor > <NUM_LIT:0> and last_time is not None:<EOL><INDENT>_time.sleep((event.time - last_time) / speed_factor)<EOL><DEDENT>last_time = event.time<EOL>key = event.scan_code or event.name<EOL>press(key) if event.event_type == KEY_DOWN else release(key)<EOL><DEDENT>restore_modifiers(state)<EOL>
Plays a sequence of recorded events, maintaining the relative time
intervals. If speed_factor is <= 0 then the actions are replayed as fast
as the OS allows. Pairs well with `record()`.

Note: the current keyboard state is cleared at the beginning and restored at
the end of the function.