diff --git a/src/events.rs b/src/events.rs index a508b589fd..690db4a1c3 100644 --- a/src/events.rs +++ b/src/events.rs @@ -95,7 +95,7 @@ pub enum DeviceEvent { Removed, Motion { axis: AxisId, value: f64 }, Button { button: ButtonId, state: ElementState }, - Key(KeyboardInput), + Key(DeviceKeyboardInput), Text { codepoint: char }, } @@ -123,6 +123,24 @@ pub struct KeyboardInput { pub modifiers: ModifiersState } +#[derive(Debug, Clone, Copy)] +pub struct DeviceKeyboardInput { + /// Identifies the physical key pressed + /// + /// This should not change if the user adjusts the host's keyboard map. Use when the physical location of the + /// key is more important than the key's host GUI semantics, such as for movement controls in a first-person + /// game. + pub scancode: ScanCode, + + pub state: ElementState, + + /// Identifies the semantic meaning of the key + /// + /// Use when the semantics of the key are more important than the physical location of the key, such as when + /// implementing appropriate behavior for "page up." + pub virtual_keycode: Option, +} + #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] pub enum TouchPhase { Started, diff --git a/src/platform/linux/x11/mod.rs b/src/platform/linux/x11/mod.rs index cddbd26588..5a58af8072 100644 --- a/src/platform/linux/x11/mod.rs +++ b/src/platform/linux/x11/mod.rs @@ -8,7 +8,7 @@ pub mod ffi; use platform::PlatformSpecificWindowBuilderAttributes; use {CreationError, Event, EventsLoopClosed, WindowEvent, DeviceEvent, AxisId, ButtonId, - KeyboardInput, ControlFlow}; + KeyboardInput, DeviceKeyboardInput, ControlFlow}; use std::{mem, ptr, slice}; use std::sync::{Arc, Mutex, Weak}; @@ -533,7 +533,7 @@ impl EventsLoop { // TODO: Use xkbcommon for keysym and text decoding let xev: &ffi::XIRawEvent = unsafe { &*(xev.data as *const _) }; let xkeysym = unsafe { (self.display.xlib.XKeycodeToKeysym)(self.display.display, xev.detail as ffi::KeyCode, 0) }; - callback(Event::DeviceEvent { device_id: mkdid(xev.deviceid), event: DeviceEvent::Key(KeyboardInput { + callback(Event::DeviceEvent { device_id: mkdid(xev.deviceid), event: DeviceEvent::Key(DeviceKeyboardInput { scancode: xev.detail as u32, virtual_keycode: events::keysym_to_element(xkeysym as libc::c_uint), state: match xev.evtype { @@ -541,7 +541,6 @@ impl EventsLoop { ffi::XI_RawKeyRelease => Released, _ => unreachable!(), }, - modifiers: ::events::ModifiersState::default(), })}); }