Ignore synthetic key presses (#4514)
This PR discards "synthetic" winit keypresses, as discussed in the issue #4513. * Closes https://github.com/emilk/egui/issues/4513
This commit is contained in:
parent
8321f64f6e
commit
262a8bcf98
|
|
@ -31,6 +31,7 @@ pub(crate) use profiling_scopes::*;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::{PhysicalPosition, PhysicalSize},
|
dpi::{PhysicalPosition, PhysicalSize},
|
||||||
|
event::ElementState,
|
||||||
event_loop::EventLoopWindowTarget,
|
event_loop::EventLoopWindowTarget,
|
||||||
window::{CursorGrabMode, Window, WindowButtons, WindowLevel},
|
window::{CursorGrabMode, Window, WindowButtons, WindowLevel},
|
||||||
};
|
};
|
||||||
|
|
@ -368,7 +369,21 @@ impl State {
|
||||||
consumed: self.egui_ctx.wants_keyboard_input(),
|
consumed: self.egui_ctx.wants_keyboard_input(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput { event, .. } => {
|
WindowEvent::KeyboardInput {
|
||||||
|
event,
|
||||||
|
is_synthetic,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
// Winit generates fake "synthetic" KeyboardInput events when the focus
|
||||||
|
// is changed to the window, or away from it. Synthetic key presses
|
||||||
|
// represent no real key presses and should be ignored.
|
||||||
|
// See https://github.com/rust-windowing/winit/issues/3543
|
||||||
|
if *is_synthetic && event.state == ElementState::Pressed {
|
||||||
|
EventResponse {
|
||||||
|
repaint: true,
|
||||||
|
consumed: false,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
self.on_keyboard_input(event);
|
self.on_keyboard_input(event);
|
||||||
|
|
||||||
// When pressing the Tab key, egui focuses the first focusable element, hence Tab always consumes.
|
// When pressing the Tab key, egui focuses the first focusable element, hence Tab always consumes.
|
||||||
|
|
@ -380,6 +395,7 @@ impl State {
|
||||||
consumed,
|
consumed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
WindowEvent::Focused(focused) => {
|
WindowEvent::Focused(focused) => {
|
||||||
self.egui_input.focused = *focused;
|
self.egui_input.focused = *focused;
|
||||||
self.egui_input
|
self.egui_input
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue