@@ -197,7 +197,9 @@ impl WinitPlatform {
197
197
io. add_key_event ( Key :: LeftSuper , state. super_key ( ) ) ;
198
198
}
199
199
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);
201
203
if let Some ( txt) = & event. text {
202
204
for ch in txt. chars ( ) {
203
205
if ch != '\u{7f}' {
@@ -207,20 +209,17 @@ impl WinitPlatform {
207
209
}
208
210
}
209
211
210
- let key = event. key_without_modifiers ( ) ;
211
- let pressed = event. state == ElementState :: Pressed ;
212
-
213
212
// We map both left and right ctrl to `ModCtrl`, etc.
214
213
// imgui is told both "left control is pressed" and
215
214
// "consider the control key is pressed". Allows
216
215
// applications to use either general "ctrl" or a
217
216
// specific key. Same applies to other modifiers.
218
217
// 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 ) ;
220
219
221
220
// 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 ) ;
224
223
}
225
224
}
226
225
WindowEvent :: CursorMoved { position, .. } => {
@@ -393,7 +392,7 @@ fn to_imgui_mouse_button(button: MouseButton) -> Option<imgui::MouseButton> {
393
392
}
394
393
}
395
394
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 > {
397
396
match ( key. as_ref ( ) , location) {
398
397
( WinitKey :: Named ( NamedKey :: Tab ) , _) => Some ( Key :: Tab ) ,
399
398
( WinitKey :: Named ( NamedKey :: ArrowLeft ) , _) => Some ( Key :: LeftArrow ) ,
0 commit comments