diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 96721e4aa2..564aad0469 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -105,6 +105,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 533316e62f..7e2e3ccd9a 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -20,6 +20,7 @@ use crate::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle, }; +use crate::keyboard::Key; use crate::monitor::MonitorHandle as RootMonitorHandle; use crate::platform::pump_events::PumpStatus; use crate::window::{ @@ -468,15 +469,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,