From 085a3c3e9bbe492f26951e5a3647e54ba7ae13fa Mon Sep 17 00:00:00 2001 From: lbf Date: Tue, 3 Dec 2024 14:24:44 +0100 Subject: [PATCH] fix bug ignoring numlock when using keypad --- src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3b050f7..39c8bf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -197,7 +197,9 @@ impl WinitPlatform { io.add_key_event(Key::LeftSuper, state.super_key()); } WindowEvent::KeyboardInput { ref event, .. } => { - if event.state.is_pressed() { + let is_pressed = event.state.is_pressed(); + if is_pressed { + //println!("{:#?}", event); if let Some(txt) = &event.text { for ch in txt.chars() { if ch != '\u{7f}' { @@ -207,20 +209,17 @@ impl WinitPlatform { } } - let key = event.key_without_modifiers(); - let pressed = event.state == ElementState::Pressed; - // We map both left and right ctrl to `ModCtrl`, etc. // imgui is told both "left control is pressed" and // "consider the control key is pressed". Allows // applications to use either general "ctrl" or a // specific key. Same applies to other modifiers. // https://github.com/ocornut/imgui/issues/5047 - handle_key_modifier(io, &key, pressed); + handle_key_modifier(io, &event.key_without_modifiers(), is_pressed); // Add main key event - if let Some(key) = to_imgui_key(key, event.location) { - io.add_key_event(key, pressed); + if let Some(key) = to_imgui_key(&event.logical_key, event.location) { + io.add_key_event(key, is_pressed); } } WindowEvent::CursorMoved { position, .. } => { @@ -393,7 +392,7 @@ fn to_imgui_mouse_button(button: MouseButton) -> Option { } } -fn to_imgui_key(key: winit::keyboard::Key, location: KeyLocation) -> Option { +fn to_imgui_key(key: &winit::keyboard::Key, location: KeyLocation) -> Option { match (key.as_ref(), location) { (WinitKey::Named(NamedKey::Tab), _) => Some(Key::Tab), (WinitKey::Named(NamedKey::ArrowLeft), _) => Some(Key::LeftArrow),