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