Ignore extra SHIFT and ALT when matching modifiers#3769
Conversation
|
Seems like we are hitting this winit bug: rust-windowing/winit#3078 |
|
Fix for winit in rust-windowing/winit#3361 |
|
This should do the right think on Windows and Linux (I hope), but for macOS we have to wait for rust-windowing/winit#3361 |
|
My application was distinguishing between shortcuts with and without Shift, which this breaks. It also causes surprising behavior: let change = if i.consume_key(Modifiers::COMMAND | Modifiers::SHIFT, Key::Plus) {
// correctly captures Command-Shift-Plus, even though it shouldn't anymore?
10
} else if i.consume_key(Modifiers::COMMAND, Key::Plus) {
// never triggers
1
} else if i.consume_key(Modifiers::COMMAND | Modifiers::SHIFT, Key::Minus) {
// never triggers
-10
} else if i.consume_key(Modifiers::COMMAND, Key::Minus) {
// correctly captures Command-Minus
-1
} else {
return;
};If not for Possibly related: when upgrading from 0.23.0 to 0.27.1 I had to set |
|
This almost replicates the previous behavior, except that let mut change = None;
i.events.retain(|event| {
match event {
Event::Key { physical_key: Some(Key::Equals), modifiers, pressed: true, .. } => {
change = Some(if modifiers.shift { 10 } else { 1 });
false
}
Event::Key { physical_key: Some(Key::Minus), modifiers, pressed: true, .. } => {
change = Some(if modifiers.shift { -10 } else { -1 });
false
}
_ => true,
}
}); |
|
Pressing shift and minus at the same time will on my keyboard produce the underscore character: You are trying to check for a physical key, when egui uses logical keys. See https://docs.rs/egui/latest/egui/enum.Event.html#variant.Key and #3653 for more |

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 pressingSHIFT =,so the keyboard shortcut looking for
CTRL +should ignore the SHIFT key.consume_keyandconsume_shortcutyou should match most specific shortcuts first,i.e. check for
Cmd-Shift-S("Save as…") beforeCmd-S("Save"),so that a user pressing
Cmd-Shift-Swon't trigger the wrong command!@abey79 You reported problem using
Cmd +andCmd -to zoom - does this fix it for you?You can run with
RUST_LOG=egui_winit=trace cargo runto see a printout of how winit reports the logical and physical keys, and how egui interprets them.Weirdly, on Mac winit reports
SHIFT =as+, butCMD SHIFT =as=(on an English keyboard) so things are… difficult.