def restore_state(scan_codes):
_listener.is_replaying = True<EOL>with _pressed_events_lock:<EOL><INDENT>current = set(_pressed_events)<EOL><DEDENT>target = set(scan_codes)<EOL>for scan_code in current - target:<EOL><INDENT>_os_keyboard.release(scan_code)<EOL><DEDENT>for scan_code in target - current:<EOL><INDENT>_os_keyboard.press(scan_code)<EOL><DEDENT>_listener.is_replaying = False<EOL>
Given a list of scan_codes ensures these keys, and only these keys, are
pressed. Pairs well with `stash_state`, alternative to `restore_modifiers`.