@@ -197,7 +197,9 @@ impl WinitPlatform {
197197 io. add_key_event ( Key :: LeftSuper , state. super_key ( ) ) ;
198198 }
199199 WindowEvent :: KeyboardInput { ref event, .. } => {
200- if event. state . is_pressed ( ) {
200+ let is_pressed = event. state . is_pressed ( ) ;
201+ if is_pressed {
202+ //println!("{:#?}", event);
201203 if let Some ( txt) = & event. text {
202204 for ch in txt. chars ( ) {
203205 if ch != '\u{7f}' {
@@ -207,20 +209,17 @@ impl WinitPlatform {
207209 }
208210 }
209211
210- let key = event. key_without_modifiers ( ) ;
211- let pressed = event. state == ElementState :: Pressed ;
212-
213212 // We map both left and right ctrl to `ModCtrl`, etc.
214213 // imgui is told both "left control is pressed" and
215214 // "consider the control key is pressed". Allows
216215 // applications to use either general "ctrl" or a
217216 // specific key. Same applies to other modifiers.
218217 // https://github.com/ocornut/imgui/issues/5047
219- handle_key_modifier ( io, & key , pressed ) ;
218+ handle_key_modifier ( io, & event . key_without_modifiers ( ) , is_pressed ) ;
220219
221220 // Add main key event
222- if let Some ( key) = to_imgui_key ( key , event. location ) {
223- io. add_key_event ( key, pressed ) ;
221+ if let Some ( key) = to_imgui_key ( & event . logical_key , event. location ) {
222+ io. add_key_event ( key, is_pressed ) ;
224223 }
225224 }
226225 WindowEvent :: CursorMoved { position, .. } => {
@@ -393,7 +392,7 @@ fn to_imgui_mouse_button(button: MouseButton) -> Option<imgui::MouseButton> {
393392 }
394393}
395394
396- fn to_imgui_key ( key : winit:: keyboard:: Key , location : KeyLocation ) -> Option < Key > {
395+ fn to_imgui_key ( key : & winit:: keyboard:: Key , location : KeyLocation ) -> Option < Key > {
397396 match ( key. as_ref ( ) , location) {
398397 ( WinitKey :: Named ( NamedKey :: Tab ) , _) => Some ( Key :: Tab ) ,
399398 ( WinitKey :: Named ( NamedKey :: ArrowLeft ) , _) => Some ( Key :: LeftArrow ) ,
0 commit comments