pub fn write_modifiers_keys_state_system(
    mut ev_keyboard_input: EventReader<KeyboardInput>,
    mut ev_focus: EventReader<KeyboardFocusLost>,
    mut modifier_keys_state: ResMut<ModifierKeysState>,
) {
    // If window focus is lost, clear all modifiers to avoid stuck keys.
    if !ev_focus.is_empty() {
        ev_focus.clear();
        modifier_keys_state.reset();
    }

    for event in ev_keyboard_input.read() {
        let KeyboardInput {
            logical_key, state, ..
        } = event;
        match logical_key {
            Key::Shift => {
                modifier_keys_state.shift = state.is_pressed();
            }
            Key::Control => {
                modifier_keys_state.ctrl = state.is_pressed();
            }
            Key::Alt => {
                modifier_keys_state.alt = state.is_pressed();
            }
            Key::Super | Key::Meta => {
                modifier_keys_state.win = state.is_pressed();
            }
            _ => {}
        };
    }
}
Reads [`KeyboardInput`] events to update the [`ModifierKeysState`] resource.
src/input.rs