Android: Add KeyEvent handling (#1839)

This commit is contained in:
mmacedo 2021-02-23 18:35:38 -03:00 committed by GitHub
parent 10a94c0794
commit 952edcb804
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View file

@ -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.

View file

@ -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<T: 'static> EventLoop<T> {
}
}
}
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);