diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4fe474..e57ea66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- On Android, `InputEvent::KeyEvent` is partially implemented providing the key scancode. - Added `is_maximized` method to `Window`. - On Windows, fix bug where clicking the decoration bar would make the cursor blink. - On Windows, fix bug causing newly created windows to erroneously display the "wait" (spinning) cursor. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index a6d197b6..0365a40e 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -8,7 +8,7 @@ use crate::{ }; use ndk::{ configuration::Configuration, - event::{InputEvent, MotionAction}, + event::{InputEvent, KeyAction, MotionAction}, looper::{ForeignLooper, Poll, ThreadLooper}, }; use ndk_glue::{Event, Rect}; @@ -239,9 +239,31 @@ impl EventLoop { } } } - InputEvent::KeyEvent(_) => { - // TODO - handled = false; + InputEvent::KeyEvent(key) => { + let state = match key.action() { + KeyAction::Down => event::ElementState::Pressed, + KeyAction::Up => event::ElementState::Released, + _ => event::ElementState::Released, + }; + let event = event::Event::WindowEvent { + window_id, + event: event::WindowEvent::KeyboardInput { + device_id, + input: event::KeyboardInput { + scancode: key.scan_code() as u32, + state, + virtual_keycode: None, + modifiers: event::ModifiersState::default(), + }, + is_synthetic: false, + }, + }; + call_event_handler!( + event_handler, + self.window_target(), + control_flow, + event + ); } }; input_queue.finish_event(event, handled);