Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some Keys #5400

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,11 @@ impl State {
physical_key
);

// "Logical OR physical key" is a fallback mechanism for keyboard layouts without Latin characters: it lets them
// "physical OR logical key" is a fallback mechanism for keyboard layouts without Latin characters: it lets them
// emit events as if the corresponding keys from the Latin layout were pressed. In this case, clipboard shortcuts
// are mapped to the physical keys that normally contain C, X, V, etc.
// See also: https://github.com/emilk/egui/issues/3653
if let Some(active_key) = logical_key.or(physical_key) {
if let Some(active_key) = physical_key.or(logical_key) {
if pressed {
if is_cut_command(self.egui_input.modifiers, active_key) {
self.egui_input.events.push(egui::Event::Cut);
Expand Down Expand Up @@ -1083,6 +1083,15 @@ fn key_from_named_key(named_key: winit::keyboard::NamedKey) -> Option<egui::Key>
NamedKey::Delete => Key::Delete,
NamedKey::Insert => Key::Insert,
NamedKey::Escape => Key::Escape,

NamedKey::Alt => Key::AltLeft,
NamedKey::Control => Key::ControlLeft,
NamedKey::Shift => Key::ShiftLeft,

NamedKey::CapsLock => Key::CapsLock,
NamedKey::NumLock => Key::NumLock,
NamedKey::ScrollLock => Key::ScrollLock,

NamedKey::Cut => Key::Cut,
NamedKey::Copy => Key::Copy,
NamedKey::Paste => Key::Paste,
Expand Down Expand Up @@ -1136,6 +1145,7 @@ fn key_from_key_code(key: winit::keyboard::KeyCode) -> Option<egui::Key> {
use winit::keyboard::KeyCode;

Some(match key {
// Commands:
KeyCode::ArrowDown => Key::ArrowDown,
KeyCode::ArrowLeft => Key::ArrowLeft,
KeyCode::ArrowRight => Key::ArrowRight,
Expand All @@ -1153,6 +1163,21 @@ fn key_from_key_code(key: winit::keyboard::KeyCode) -> Option<egui::Key> {
KeyCode::PageUp => Key::PageUp,
KeyCode::PageDown => Key::PageDown,

KeyCode::AltLeft => Key::AltLeft,
KeyCode::AltRight => Key::AltRight,
KeyCode::ControlLeft => Key::ControlLeft,
KeyCode::ControlRight => Key::ControlRight,
KeyCode::ShiftLeft => Key::ShiftLeft,
KeyCode::ShiftRight => Key::ShiftRight,

KeyCode::CapsLock => Key::CapsLock,
KeyCode::NumLock => Key::NumLock,
KeyCode::ScrollLock => Key::ScrollLock,

KeyCode::Cut => Key::Cut,
KeyCode::Copy => Key::Copy,
KeyCode::Paste => Key::Paste,

// Punctuation
KeyCode::Space => Key::Space,
KeyCode::Comma => Key::Comma,
Expand All @@ -1166,9 +1191,6 @@ fn key_from_key_code(key: winit::keyboard::KeyCode) -> Option<egui::Key> {
KeyCode::Backquote => Key::Backtick,
KeyCode::Quote => Key::Quote,

KeyCode::Cut => Key::Cut,
KeyCode::Copy => Key::Copy,
KeyCode::Paste => Key::Paste,
KeyCode::Minus | KeyCode::NumpadSubtract => Key::Minus,
KeyCode::NumpadAdd => Key::Plus,
KeyCode::Equal => Key::Equals,
Expand Down
45 changes: 45 additions & 0 deletions crates/egui/src/data/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ pub enum Key {
PageUp,
PageDown,

AltLeft,
AltRight,
ControlLeft,
ControlRight,
ShiftLeft,
ShiftRight,

CapsLock,
NumLock,
ScrollLock,

Copy,
Cut,
Paste,
Expand Down Expand Up @@ -201,6 +212,18 @@ impl Key {
Self::End,
Self::PageUp,
Self::PageDown,
// Alt Ctrl Shift
Self::AltLeft,
Self::AltRight,
Self::ControlLeft,
Self::ControlRight,
Self::ShiftLeft,
Self::ShiftRight,
// Lock
Self::CapsLock,
Self::NumLock,
Self::ScrollLock,
// Copy Cut Paste
Self::Copy,
Self::Cut,
Self::Paste,
Expand Down Expand Up @@ -325,6 +348,17 @@ impl Key {
"PageUp" => Self::PageUp,
"PageDown" => Self::PageDown,

"CapsLock" => Self::CapsLock,
"NumLock" => Self::NumLock,
"ScrollLock" => Self::ScrollLock,

"AltLeft" => Self::AltLeft,
"AltRight" => Self::AltRight,
"ControlLeft" => Self::ControlLeft,
"ControlRight" => Self::ControlRight,
"ShiftLeft" => Self::ShiftLeft,
"ShiftRight" => Self::ShiftRight,

"Copy" => Self::Copy,
"Cut" => Self::Cut,
"Paste" => Self::Paste,
Expand Down Expand Up @@ -474,6 +508,17 @@ impl Key {
Self::PageUp => "PageUp",
Self::PageDown => "PageDown",

Self::CapsLock => "CapsLock",
Self::NumLock => "NumLock",
Self::ScrollLock => "ScrollLock",

Self::AltLeft => "AltLeft",
Self::AltRight => "AltRight",
Self::ControlLeft => "ControlLeft",
Self::ControlRight => "ControlRight",
Self::ShiftLeft => "ShiftLeft",
Self::ShiftRight => "ShiftRight",

Self::Copy => "Copy",
Self::Cut => "Cut",
Self::Paste => "Paste",
Expand Down
Loading