diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index e56064dba3..25fe1a473c 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -110,6 +110,7 @@ changelog entry. - On Web, `Window::canvas()` now returns a reference. - On Web, `CursorGrabMode::Locked` now lets `DeviceEvent::MouseMotion` return raw data, not OS accelerated, if the browser supports it. +- On Android, when `keycode` can be represented as character, its textual representation is provided in `KeyEvent::text`. - `(Active)EventLoop::create_custom_cursor()` now returns a `Result`. - Changed how `ModifiersState` is serialized by Serde. - `VideoModeHandle::refresh_rate_millihertz()` and `bit_depth()` now return a `Option`. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 0d07506a02..f066f860fb 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -9,6 +9,7 @@ use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction}; use android_activity::{ AndroidApp, AndroidAppWaker, ConfigurationRef, InputStatus, MainEvent, Rect, }; +use smol_str::SmolStr; use tracing::{debug, trace, warn}; use crate::application::ApplicationHandler; @@ -470,15 +471,22 @@ impl EventLoop { &mut self.combining_accent, ); + let logical_key = keycodes::to_logical(key_char, keycode); + let text = if state == event::ElementState::Pressed { + logical_key.to_text().map(SmolStr::new) + } else { + None + }; + let event = event::WindowEvent::KeyboardInput { device_id: Some(DeviceId::from_raw(key.device_id() as i64)), event: event::KeyEvent { state, physical_key: keycodes::to_physical_key(keycode), - logical_key: keycodes::to_logical(key_char, keycode), + logical_key, location: keycodes::to_location(keycode), repeat: key.repeat_count() > 0, - text: None, + text, platform_specific: KeyEventExtra {}, }, is_synthetic: false,