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 2 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
20 changes: 20 additions & 0 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
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::CapsLock => Key::CapsLock,
NamedKey::NumLock => Key::NumLock,
NamedKey::ScrollLock => Key::ScrollLock,

NamedKey::Alt => Key::Alt,
NamedKey::Control => Key::Control,
NamedKey::Shift => Key::Shift,

NamedKey::Cut => Key::Cut,
NamedKey::Copy => Key::Copy,
NamedKey::Paste => Key::Paste,
Expand Down Expand Up @@ -1153,6 +1162,17 @@ fn key_from_key_code(key: winit::keyboard::KeyCode) -> Option<egui::Key> {
KeyCode::PageUp => Key::PageUp,
KeyCode::PageDown => Key::PageDown,

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

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

// Punctuation
KeyCode::Space => Key::Space,
KeyCode::Comma => Key::Comma,
Expand Down
42 changes: 42 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,

CapsLock,
NumLock,
ScrollLock,

Alt,
AltRight,
Control,
ControlRight,
Shift,
ShiftRight,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A) it's weird that there is both Alt and AltRight, but not AltLeft
B) on the PR preview (https://egui-pr-preview.github.io/pr/5400-patch150/) the Right versions doesn't work at all.

I think we either should just have a single Alt, OR we should have AltLeft and AltRight, and make sure it works everywhere

Copy link
Contributor Author

@rustbasic rustbasic Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, Alt, Ctrl, and Shift basically mean Left.
=> Marked as Left and Right.

logical_key.or(physical_key) to physical_key.or(logical_key)
This works fine, but I'm not sure if it has any negative effects elsewhere.


Copy,
Cut,
Paste,
Expand Down Expand Up @@ -201,6 +212,15 @@ impl Key {
Self::End,
Self::PageUp,
Self::PageDown,
Self::CapsLock,
Self::NumLock,
Self::ScrollLock,
Self::Alt,
Self::AltRight,
Self::Control,
Self::ControlRight,
Self::Shift,
Self::ShiftRight,
Self::Copy,
Self::Cut,
Self::Paste,
Expand Down Expand Up @@ -325,6 +345,17 @@ impl Key {
"PageUp" => Self::PageUp,
"PageDown" => Self::PageDown,

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

"Alt" => Self::Alt,
"AltRight" => Self::AltRight,
"Control" => Self::Control,
"ControlRight" => Self::ControlRight,
"Shift" => Self::Shift,
"ShiftRight" => Self::ShiftRight,

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

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

Self::Alt => "Alt",
Self::AltRight => "AltRight",
Self::Control => "Control",
Self::ControlRight => "ControlRight",
Self::Shift => "Shift",
Self::ShiftRight => "ShiftRight",

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