Skip to content

Commit

Permalink
android: forward Key::Characters as KeyEvent::text on press
Browse files Browse the repository at this point in the history
Whenever we press a logical key that corresponds to a `Key::Character`
with a unicode string, we now also forward that as the `.text` for the
`KeyEvent`.
  • Loading branch information
rib committed Jan 30, 2024
1 parent 9ab5bd6 commit b539caf
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
error,
event::{self, Force, InnerSizeWriter, StartCause},
event_loop::{self, ControlFlow, DeviceEvents, EventLoopWindowTarget as RootELW},
keyboard::Key,
platform::pump_events::PumpStatus,
window::{
self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel,
Expand Down Expand Up @@ -450,17 +451,27 @@ impl<T: 'static> EventLoop<T> {
&mut self.combining_accent,
);

let logical_key = keycodes::to_logical(key_char, keycode);
let text = if let Key::Character(c) = &logical_key {
if state == event::ElementState::Pressed {
Some(c.clone())
} else {
None
}
} else {
None
};
let event = event::Event::WindowEvent {
window_id: window::WindowId(WindowId),
event: event::WindowEvent::KeyboardInput {
device_id: event::DeviceId(DeviceId(key.device_id())),
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,
Expand Down

0 comments on commit b539caf

Please sign in to comment.