1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

Ignore extra SHIFT and ALT when matching modifiers (#3769)

* Closes https://github.com/emilk/egui/issues/3626

Basically, egui now ignores extra SHIFT and ALT pressed when matching
keyboard shortcuts.
This is because SHIFT and ALT are often requires to produce some logical
keys.
For instance, typing `+` on an English keyboard requires pressing `SHIFT
=`,
so the keyboard shortcut looking for `CTRL +` should ignore the SHIFT
key.

@abey79 You reported problem using `Cmd +` and `Cmd -` to zoom - does
this fix it for you?

You can run with `RUST_LOG=egui_winit=trace cargo run` to see a printout
of how winit reports the logical and physical keys, and how egui
interprets them.

Weirdly, on Mac winit reports `SHIFT =` as `+`, but `CMD SHIFT =` as `=`
(on an English keyboard) so things are… difficult.
This commit is contained in:
Emil Ernerfeldt
2024-01-05 10:53:14 +01:00
committed by GitHub
parent 1efa660149
commit 9faf4b44ff
5 changed files with 145 additions and 30 deletions

View File

@@ -689,6 +689,15 @@ impl State {
let logical_key = key_from_winit_key(logical_key);
// Helpful logging to enable when adding new key support
log::trace!(
"logical {:?} -> {:?}, physical {:?} -> {:?}",
event.logical_key,
logical_key,
event.physical_key,
physical_key
);
if let Some(logical_key) = logical_key {
if pressed {
if is_cut_command(self.egui_input.modifiers, logical_key) {
@@ -1064,9 +1073,8 @@ fn key_from_key_code(key: winit::keyboard::KeyCode) -> Option<egui::Key> {
KeyCode::Minus | KeyCode::NumpadSubtract => Key::Minus,
// Using Mac the key with the Plus sign on it is reported as the Equals key
// (with both English and Swedish keyboard).
KeyCode::Equal | KeyCode::NumpadAdd => Key::PlusEquals,
KeyCode::NumpadAdd => Key::Plus,
KeyCode::Equal => Key::Equals,
KeyCode::Digit0 | KeyCode::Numpad0 => Key::Num0,
KeyCode::Digit1 | KeyCode::Numpad1 => Key::Num1,