pub fn write_keyboard_input_events_system(
    modifier_keys_state: Res<ModifierKeysState>,
    focused_non_window_egui_context: Option<Res<FocusedNonWindowEguiContext>>,
    #[cfg(all(
        feature = "manage_clipboard",
        not(target_os = "android"),
        not(target_arch = "wasm32")
    ))]
    mut egui_clipboard: ResMut<crate::EguiClipboard>,
    mut keyboard_input_reader: EventReader<KeyboardInput>,
    mut egui_input_event_writer: EventWriter<EguiInputEvent>,
    egui_contexts: Query<&EguiContextSettings, With<EguiContext>>,
) {
    let modifiers = modifier_keys_state.to_egui_modifiers();
    for event in keyboard_input_reader.read() {
        let context = focused_non_window_egui_context
            .as_deref()
            .map_or(event.window, |context| context.0);

        let Some(context_settings) = egui_contexts.get_some(context) else {
            continue;
        };

        if !context_settings
            .input_system_settings
            .run_write_keyboard_input_events_system
        {
            continue;
        }

        if modifier_keys_state.text_input_is_allowed() && event.state.is_pressed() {
            match &event.logical_key {
                Key::Character(char) if char.matches(char::is_control).count() == 0 => {
                    egui_input_event_writer.write(EguiInputEvent {
                        context,
                        event: egui::Event::Text(char.to_string()),
                    });
                }
                Key::Space => {
                    egui_input_event_writer.write(EguiInputEvent {
                        context,
                        event: egui::Event::Text(" ".to_string()),
                    });
                }
                _ => (),
            }
        }

        let key = crate::helpers::bevy_to_egui_key(&event.logical_key);
        let physical_key = crate::helpers::bevy_to_egui_physical_key(&event.key_code);

        // "Logical OR physical key" is a fallback mechanism for keyboard layouts without Latin characters
        // See: https://github.com/emilk/egui/blob/66c73b9cbfbd4d44489fc6f6a840d7d82bc34389/crates/egui-winit/src/lib.rs#L760
        let (Some(key), physical_key) = (key.or(physical_key), physical_key) else {
            continue;
        };

        let egui_event = egui::Event::Key {
            key,
            pressed: event.state.is_pressed(),
            repeat: false,
            modifiers,
            physical_key,
        };
        egui_input_event_writer.write(EguiInputEvent {
            context,
            event: egui_event,
        });

        // We also check that it's a `ButtonState::Pressed` event, as we don't want to
        // copy, cut or paste on the key release.
        #[cfg(all(
            feature = "manage_clipboard",
            not(target_os = "android"),
            not(target_arch = "wasm32")
        ))]
        if modifiers.command && event.state.is_pressed() {
            match key {
                egui::Key::C => {
                    egui_input_event_writer.write(EguiInputEvent {
                        context,
                        event: egui::Event::Copy,
                    });
                }
                egui::Key::X => {
                    egui_input_event_writer.write(EguiInputEvent {
                        context,
                        event: egui::Event::Cut,
                    });
                }
                egui::Key::V => {
                    if let Some(contents) = egui_clipboard.get_text() {
                        egui_input_event_writer.write(EguiInputEvent {
                            context,
                            event: egui::Event::Text(contents),
                        });
                    }
                }
                _ => {}
            }
        }
    }
}
Reads [`KeyboardInput`] events and wraps them into [`EguiInputEvent`], can redirect events to [`FocusedNonWindowEguiContext`].
src/input.rs