Add all alpha-numeric keys to egui::Key
Closes https://github.com/emilk/egui/issues/91
This commit is contained in:
parent
cbe0de83ee
commit
c6a5af19e6
3 changed files with 148 additions and 27 deletions
|
@ -235,44 +235,95 @@ pub enum Event {
|
||||||
/// State of the modifier keys. These must be fed to Egui.
|
/// State of the modifier keys. These must be fed to Egui.
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
pub struct Modifiers {
|
pub struct Modifiers {
|
||||||
/// Either of the alt keys are down (option ⌥ on Mac)
|
/// Either of the alt keys are down (option ⌥ on Mac).
|
||||||
pub alt: bool,
|
pub alt: bool,
|
||||||
/// Either of the control keys are down
|
/// Either of the control keys are down.
|
||||||
|
/// When checking for keyboard shortcuts, consider using [`Self::command`] instead.
|
||||||
pub ctrl: bool,
|
pub ctrl: bool,
|
||||||
/// Either of the shift keys are down
|
/// Either of the shift keys are down.
|
||||||
pub shift: bool,
|
pub shift: bool,
|
||||||
/// The Mac ⌘ Command key. Should always be set to `false` on other platforms.
|
/// The Mac ⌘ Command key. Should always be set to `false` on other platforms.
|
||||||
pub mac_cmd: bool,
|
pub mac_cmd: bool,
|
||||||
/// On Mac, this should be set whenever one of the ⌘ Command keys are down (same as `mac_cmd`).
|
|
||||||
/// On Windows and Linux, set this to the same value as `ctrl`.
|
/// On Windows and Linux, set this to the same value as `ctrl`.
|
||||||
|
/// On Mac, this should be set whenever one of the ⌘ Command keys are down (same as `mac_cmd`).
|
||||||
/// This is so that Egui can, for instance, select all text by checking for `command + A`
|
/// This is so that Egui can, for instance, select all text by checking for `command + A`
|
||||||
/// and it will work on both Mac and Windows.
|
/// and it will work on both Mac and Windows.
|
||||||
pub command: bool,
|
pub command: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Keyboard key name. Only covers keys used by Egui (mostly for text editing).
|
/// Keyboard keys.
|
||||||
|
///
|
||||||
|
/// Includes all keys Egui is interested in (such as `Home` and `End`)
|
||||||
|
/// plus a few that are useful for detecting keyboard shortcuts.
|
||||||
|
///
|
||||||
|
/// Many keys are omitted because they are not always physical keys (depending on keyboard language), e.g. `;` and `§`,
|
||||||
|
/// and are therefor unsuitable as keyboard shortcuts if you want your app to be portable.
|
||||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
pub enum Key {
|
pub enum Key {
|
||||||
ArrowDown,
|
ArrowDown,
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
|
|
||||||
|
Escape,
|
||||||
|
Tab,
|
||||||
Backspace,
|
Backspace,
|
||||||
Delete,
|
|
||||||
End,
|
|
||||||
Enter,
|
Enter,
|
||||||
Space,
|
Space,
|
||||||
Escape,
|
|
||||||
Home,
|
|
||||||
Insert,
|
Insert,
|
||||||
PageDown,
|
Delete,
|
||||||
|
Home,
|
||||||
|
End,
|
||||||
PageUp,
|
PageUp,
|
||||||
Tab,
|
PageDown,
|
||||||
|
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num0,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num1,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num2,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num3,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num4,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num5,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num6,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num7,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num8,
|
||||||
|
/// Either from the main row or from the numpad.
|
||||||
|
Num9,
|
||||||
|
|
||||||
A, // Used for cmd+A (select All)
|
A, // Used for cmd+A (select All)
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
D,
|
||||||
|
E,
|
||||||
|
F,
|
||||||
|
G,
|
||||||
|
H,
|
||||||
|
I,
|
||||||
|
J,
|
||||||
K, // Used for ctrl+K (delete text after cursor)
|
K, // Used for ctrl+K (delete text after cursor)
|
||||||
|
L,
|
||||||
|
M,
|
||||||
|
N,
|
||||||
|
O,
|
||||||
|
P,
|
||||||
|
Q,
|
||||||
|
R,
|
||||||
|
S,
|
||||||
|
T,
|
||||||
U, // Used for ctrl+U (delete text before cursor)
|
U, // Used for ctrl+U (delete text before cursor)
|
||||||
|
V,
|
||||||
W, // Used for ctrl+W (delete previous word)
|
W, // Used for ctrl+W (delete previous word)
|
||||||
|
X,
|
||||||
|
Y,
|
||||||
Z, // Used for cmd+Z (undo)
|
Z, // Used for cmd+Z (undo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,26 +165,60 @@ pub fn translate_virtual_key_code(key: VirtualKeyCode) -> Option<egui::Key> {
|
||||||
use VirtualKeyCode::*;
|
use VirtualKeyCode::*;
|
||||||
|
|
||||||
Some(match key {
|
Some(match key {
|
||||||
Escape => Key::Escape,
|
|
||||||
Insert => Key::Insert,
|
|
||||||
Home => Key::Home,
|
|
||||||
Delete => Key::Delete,
|
|
||||||
End => Key::End,
|
|
||||||
PageDown => Key::PageDown,
|
|
||||||
PageUp => Key::PageUp,
|
|
||||||
Left => Key::ArrowLeft,
|
|
||||||
Up => Key::ArrowUp,
|
|
||||||
Right => Key::ArrowRight,
|
|
||||||
Down => Key::ArrowDown,
|
Down => Key::ArrowDown,
|
||||||
|
Left => Key::ArrowLeft,
|
||||||
|
Right => Key::ArrowRight,
|
||||||
|
Up => Key::ArrowUp,
|
||||||
|
|
||||||
|
Escape => Key::Escape,
|
||||||
|
Tab => Key::Tab,
|
||||||
Back => Key::Backspace,
|
Back => Key::Backspace,
|
||||||
Return => Key::Enter,
|
Return => Key::Enter,
|
||||||
Tab => Key::Tab,
|
|
||||||
Space => Key::Space,
|
Space => Key::Space,
|
||||||
|
|
||||||
|
Insert => Key::Insert,
|
||||||
|
Delete => Key::Delete,
|
||||||
|
Home => Key::Home,
|
||||||
|
End => Key::End,
|
||||||
|
PageUp => Key::PageUp,
|
||||||
|
PageDown => Key::PageDown,
|
||||||
|
|
||||||
|
Key0 | Numpad0 => Key::Num0,
|
||||||
|
Key1 | Numpad1 => Key::Num1,
|
||||||
|
Key2 | Numpad2 => Key::Num2,
|
||||||
|
Key3 | Numpad3 => Key::Num3,
|
||||||
|
Key4 | Numpad4 => Key::Num4,
|
||||||
|
Key5 | Numpad5 => Key::Num5,
|
||||||
|
Key6 | Numpad6 => Key::Num6,
|
||||||
|
Key7 | Numpad7 => Key::Num7,
|
||||||
|
Key8 | Numpad8 => Key::Num8,
|
||||||
|
Key9 | Numpad9 => Key::Num9,
|
||||||
|
|
||||||
A => Key::A,
|
A => Key::A,
|
||||||
|
B => Key::B,
|
||||||
|
C => Key::C,
|
||||||
|
D => Key::D,
|
||||||
|
E => Key::E,
|
||||||
|
F => Key::F,
|
||||||
|
G => Key::G,
|
||||||
|
H => Key::H,
|
||||||
|
I => Key::I,
|
||||||
|
J => Key::J,
|
||||||
K => Key::K,
|
K => Key::K,
|
||||||
|
L => Key::L,
|
||||||
|
M => Key::M,
|
||||||
|
N => Key::N,
|
||||||
|
O => Key::O,
|
||||||
|
P => Key::P,
|
||||||
|
Q => Key::Q,
|
||||||
|
R => Key::R,
|
||||||
|
S => Key::S,
|
||||||
|
T => Key::T,
|
||||||
U => Key::U,
|
U => Key::U,
|
||||||
|
V => Key::V,
|
||||||
W => Key::W,
|
W => Key::W,
|
||||||
|
X => Key::X,
|
||||||
|
Y => Key::Y,
|
||||||
Z => Key::Z,
|
Z => Key::Z,
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -319,22 +319,58 @@ pub fn translate_key(key: &str) -> Option<egui::Key> {
|
||||||
"ArrowLeft" => Some(egui::Key::ArrowLeft),
|
"ArrowLeft" => Some(egui::Key::ArrowLeft),
|
||||||
"ArrowRight" => Some(egui::Key::ArrowRight),
|
"ArrowRight" => Some(egui::Key::ArrowRight),
|
||||||
"ArrowUp" => Some(egui::Key::ArrowUp),
|
"ArrowUp" => Some(egui::Key::ArrowUp),
|
||||||
|
|
||||||
|
"Esc" | "Escape" => Some(egui::Key::Escape),
|
||||||
|
"Tab" => Some(egui::Key::Tab),
|
||||||
"Backspace" => Some(egui::Key::Backspace),
|
"Backspace" => Some(egui::Key::Backspace),
|
||||||
"Delete" => Some(egui::Key::Delete),
|
|
||||||
"End" => Some(egui::Key::End),
|
|
||||||
"Enter" => Some(egui::Key::Enter),
|
"Enter" => Some(egui::Key::Enter),
|
||||||
"Space" => Some(egui::Key::Space),
|
"Space" => Some(egui::Key::Space),
|
||||||
"Esc" | "Escape" => Some(egui::Key::Escape),
|
|
||||||
"Help" | "Insert" => Some(egui::Key::Insert),
|
"Help" | "Insert" => Some(egui::Key::Insert),
|
||||||
|
"Delete" => Some(egui::Key::Delete),
|
||||||
"Home" => Some(egui::Key::Home),
|
"Home" => Some(egui::Key::Home),
|
||||||
"PageDown" => Some(egui::Key::PageDown),
|
"End" => Some(egui::Key::End),
|
||||||
"PageUp" => Some(egui::Key::PageUp),
|
"PageUp" => Some(egui::Key::PageUp),
|
||||||
"Tab" => Some(egui::Key::Tab),
|
"PageDown" => Some(egui::Key::PageDown),
|
||||||
|
|
||||||
|
"0" => Some(egui::Key::Num0),
|
||||||
|
"1" => Some(egui::Key::Num1),
|
||||||
|
"2" => Some(egui::Key::Num2),
|
||||||
|
"3" => Some(egui::Key::Num3),
|
||||||
|
"4" => Some(egui::Key::Num4),
|
||||||
|
"5" => Some(egui::Key::Num5),
|
||||||
|
"6" => Some(egui::Key::Num6),
|
||||||
|
"7" => Some(egui::Key::Num7),
|
||||||
|
"8" => Some(egui::Key::Num8),
|
||||||
|
"9" => Some(egui::Key::Num9),
|
||||||
|
|
||||||
"a" | "A" => Some(egui::Key::A),
|
"a" | "A" => Some(egui::Key::A),
|
||||||
|
"b" | "B" => Some(egui::Key::B),
|
||||||
|
"c" | "C" => Some(egui::Key::C),
|
||||||
|
"d" | "D" => Some(egui::Key::D),
|
||||||
|
"e" | "E" => Some(egui::Key::E),
|
||||||
|
"f" | "F" => Some(egui::Key::F),
|
||||||
|
"g" | "G" => Some(egui::Key::G),
|
||||||
|
"h" | "H" => Some(egui::Key::H),
|
||||||
|
"i" | "I" => Some(egui::Key::I),
|
||||||
|
"j" | "J" => Some(egui::Key::J),
|
||||||
"k" | "K" => Some(egui::Key::K),
|
"k" | "K" => Some(egui::Key::K),
|
||||||
|
"l" | "L" => Some(egui::Key::L),
|
||||||
|
"m" | "M" => Some(egui::Key::M),
|
||||||
|
"n" | "N" => Some(egui::Key::N),
|
||||||
|
"o" | "O" => Some(egui::Key::O),
|
||||||
|
"p" | "P" => Some(egui::Key::P),
|
||||||
|
"q" | "Q" => Some(egui::Key::Q),
|
||||||
|
"r" | "R" => Some(egui::Key::R),
|
||||||
|
"s" | "S" => Some(egui::Key::S),
|
||||||
|
"t" | "T" => Some(egui::Key::T),
|
||||||
"u" | "U" => Some(egui::Key::U),
|
"u" | "U" => Some(egui::Key::U),
|
||||||
|
"v" | "V" => Some(egui::Key::V),
|
||||||
"w" | "W" => Some(egui::Key::W),
|
"w" | "W" => Some(egui::Key::W),
|
||||||
|
"x" | "X" => Some(egui::Key::X),
|
||||||
|
"y" | "Y" => Some(egui::Key::Y),
|
||||||
"z" | "Z" => Some(egui::Key::Z),
|
"z" | "Z" => Some(egui::Key::Z),
|
||||||
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue