Fix keyboard input

Shift/Ctrl/Alt + special keys (arrow, pageup/down, home/end, ins/del)
are better supported.
This commit is contained in:
Alexandre Bury 2016-06-25 19:28:42 -07:00
parent 7ad9a6ad4d
commit 822ffa7a7b

View File

@ -28,50 +28,94 @@ pub enum Key {
/// Tabulation key /// Tabulation key
Tab, Tab,
ShiftTab, ShiftTab,
Left,
Right,
Up,
Down,
PageUp,
PageDown,
Backspace, Backspace,
Home,
ShiftHome,
CtrlHome,
CtrlShiftHome,
End,
ShiftEnd,
CtrlEnd,
CtrlShiftEnd,
/// Delete key
Del,
ShiftDel,
CtrlDel,
CtrlShiftDel,
/// Insert key.
Ins,
/// Insert key while ctrl is pressed.
CtrlIns,
/// Escape key. /// Escape key.
Esc, Esc,
/// The 5 in the center of the keypad, when numlock is disabled. /// The 5 in the center of the keypad, when numlock is disabled.
NumpadCenter, NumpadCenter,
CtrlPageUp,
CtrlPageDown, Left,
ShiftUp,
ShiftDown,
/// Left arrow while shift is pressed. /// Left arrow while shift is pressed.
ShiftLeft, ShiftLeft,
AltLeft,
AltShiftLeft,
CtrlLeft,
CtrlShiftLeft,
CtrlAltLeft,
Right,
/// Right arrow while shift is pressed. /// Right arrow while shift is pressed.
ShiftRight, ShiftRight,
CtrlShiftLeft, AltRight,
CtrlShiftRight, AltShiftRight,
CtrlShiftUp,
CtrlShiftDown,
CtrlLeft,
CtrlRight, CtrlRight,
CtrlShiftRight,
CtrlAltRight,
Up,
ShiftUp,
AltUp,
AltShiftUp,
CtrlUp, CtrlUp,
CtrlShiftUp,
CtrlAltUp,
Down,
ShiftDown,
AltDown,
AltShiftDown,
CtrlDown, CtrlDown,
CtrlShiftDown,
CtrlAltDown,
PageUp,
ShiftPageUp,
AltPageUp,
AltShiftPageUp,
CtrlPageUp,
CtrlShiftPageUp,
CtrlAltPageUp,
PageDown,
ShiftPageDown,
AltPageDown,
AltShiftPageDown,
CtrlPageDown,
CtrlShiftPageDown,
CtrlAltPageDown,
Home,
ShiftHome,
AltHome,
AltShiftHome,
CtrlHome,
CtrlShiftHome,
CtrlAltHome,
End,
ShiftEnd,
AltEnd,
AltShiftEnd,
CtrlEnd,
CtrlShiftEnd,
CtrlAltEnd,
/// Delete key
Del,
ShiftDel,
AltDel,
AltShiftDel,
CtrlDel,
CtrlShiftDel,
/// Insert key.
Ins,
/// Insert key while ctrl is pressed.
CtrlIns,
AltIns,
CtrlAltIns,
F(u8), F(u8),
CtrlF(u8), CtrlF(u8),
ShiftF(u8), ShiftF(u8),
@ -93,24 +137,73 @@ impl Key {
27 => Key::Esc, 27 => Key::Esc,
// `Backspace` sends 127, but Ctrl-H sends `Backspace` // `Backspace` sends 127, but Ctrl-H sends `Backspace`
127 | ncurses::KEY_BACKSPACE => Key::Backspace, 127 | ncurses::KEY_BACKSPACE => Key::Backspace,
// Values under 256 are chars.
// Values 512 and above are probably extensions
// Those keys don't seem to be documented... // Those keys don't seem to be documented...
515 => Key::CtrlDel, 519 => Key::AltDel,
516 => Key::CtrlShiftDel, 520 => Key::AltShiftDel,
521 => Key::CtrlDown, 521 => Key::CtrlDel,
522 => Key::CtrlShiftDown, 522 => Key::CtrlShiftDel,
526 => Key::CtrlEnd, // 523: CtrlAltDel?
527 => Key::CtrlShiftEnd,
531 => Key::CtrlHome, // 524?
532 => Key::CtrlShiftHome,
536 => Key::CtrlIns, 525 => Key::AltDown,
541 => Key::CtrlLeft, 526 => Key::AltShiftDown,
542 => Key::CtrlShiftLeft, 527 => Key::CtrlDown,
546 => Key::CtrlPageDown, 528 => Key::CtrlShiftDown,
551 => Key::CtrlPageUp, 529 => Key::CtrlAltDown,
556 => Key::CtrlRight,
557 => Key::CtrlShiftRight, 530 => Key::AltEnd,
562 => Key::CtrlUp, 531 => Key::AltShiftEnd,
563 => Key::CtrlShiftUp, 532 => Key::CtrlEnd,
533 => Key::CtrlShiftEnd,
534 => Key::CtrlAltEnd,
535 => Key::AltHome,
536 => Key::AltShiftHome,
537 => Key::CtrlHome,
538 => Key::CtrlShiftHome,
539 => Key::CtrlAltHome,
540 => Key::AltIns,
// 541: AltShiftIns?
542 => Key::CtrlIns,
// 543: CtrlShiftIns?
544 => Key::CtrlAltIns,
545 => Key::AltLeft,
546 => Key::AltShiftLeft,
547 => Key::CtrlLeft,
548 => Key::CtrlShiftLeft,
549 => Key::CtrlAltLeft,
550 => Key::AltPageDown,
551 => Key::AltShiftPageDown,
552 => Key::CtrlPageDown,
553 => Key::CtrlShiftPageDown,
554 => Key::CtrlAltPageDown,
555 => Key::AltPageUp,
556 => Key::AltShiftPageUp,
557 => Key::CtrlPageUp,
558 => Key::CtrlShiftPageUp,
559 => Key::CtrlAltPageUp,
560 => Key::AltRight,
561 => Key::AltShiftRight,
562 => Key::CtrlRight,
563 => Key::CtrlShiftRight,
564 => Key::CtrlAltRight,
// 565?
566 => Key::AltUp,
567 => Key::AltShiftUp,
568 => Key::CtrlUp,
569 => Key::CtrlShiftUp,
570 => Key::CtrlAltUp,
ncurses::KEY_B2 => Key::NumpadCenter, ncurses::KEY_B2 => Key::NumpadCenter,
ncurses::KEY_DC => Key::Del, ncurses::KEY_DC => Key::Del,
ncurses::KEY_IC => Key::Ins, ncurses::KEY_IC => Key::Ins,
@ -130,6 +223,8 @@ impl Key {
ncurses::KEY_SHOME => Key::ShiftHome, ncurses::KEY_SHOME => Key::ShiftHome,
ncurses::KEY_SEND => Key::ShiftEnd, ncurses::KEY_SEND => Key::ShiftEnd,
ncurses::KEY_SDC => Key::ShiftDel, ncurses::KEY_SDC => Key::ShiftDel,
ncurses::KEY_SNEXT => Key::ShiftPageDown,
ncurses::KEY_SPREVIOUS => Key::ShiftPageUp,
// All Fn keys use the same enum with associated number // All Fn keys use the same enum with associated number
f @ ncurses::KEY_F1...ncurses::KEY_F12 => Key::F((f - ncurses::KEY_F0) as u8), f @ ncurses::KEY_F1...ncurses::KEY_F12 => Key::F((f - ncurses::KEY_F0) as u8),
f @ 277...288 => Key::ShiftF((f - 281 + 5) as u8), f @ 277...288 => Key::ShiftF((f - 281 + 5) as u8),
@ -159,44 +254,87 @@ impl fmt::Display for Key {
"{}", "{}",
match key { match key {
Key::NumpadCenter => "Numpad center", Key::NumpadCenter => "Numpad center",
Key::Backspace => "Backspace",
Key::Enter => "Enter",
Key::Tab => "Tab",
Key::ShiftTab => "Shift-Tab",
Key::PageUp => "PageUp",
Key::ShiftPageUp => "Shift-PageUp",
Key::AltPageUp => "Alt-PageUp",
Key::AltShiftPageUp => "Alt-Shift-PageUp",
Key::CtrlPageUp => "Ctrl-PageUp",
Key::CtrlShiftPageUp => "Ctrl-Shift-PageUp",
Key::CtrlAltPageUp => "Ctrl-Alt-PageUp",
Key::PageDown => "PageDown",
Key::ShiftPageDown => "Shift-PageDown",
Key::AltPageDown => "Alt-PageDown",
Key::AltShiftPageDown => "Alt-Shift-PageDown",
Key::CtrlPageDown => "Ctrl-PageDown",
Key::CtrlShiftPageDown => "Ctrl-Shift-PageDown",
Key::CtrlAltPageDown => "Ctrl-Alt-PageDown",
Key::Left => "Left", Key::Left => "Left",
Key::Right => "Right",
Key::Down => "Down",
Key::Up => "Up",
Key::CtrlShiftLeft => "Ctrl-Shift-Left",
Key::CtrlShiftRight => "Ctrl-Shift-Right",
Key::CtrlShiftUp => "Ctrl-Shift-Up",
Key::CtrlShiftDown => "Ctrl-Shift-Down",
Key::ShiftUp => "Shift-Up",
Key::ShiftDown => "Shift-Down",
Key::ShiftLeft => "Shift-Left", Key::ShiftLeft => "Shift-Left",
Key::AltLeft => "Alt-Left",
Key::AltShiftLeft => "Alt-Shift-Left",
Key::CtrlLeft => "Ctrl-Left",
Key::CtrlShiftLeft => "Ctrl-Shift-Left",
Key::CtrlAltLeft => "Ctrl-Alt-Left",
Key::Right => "Right",
Key::ShiftRight => "Shift-Right", Key::ShiftRight => "Shift-Right",
Key::AltRight => "Alt-Right",
Key::AltShiftRight => "Alt-Shift-Right",
Key::CtrlRight => "Ctrl-Right",
Key::CtrlShiftRight => "Ctrl-Shift-Right",
Key::CtrlAltRight => "Ctrl-Alt-Right",
Key::Down => "Down",
Key::ShiftDown => "Shift-Down",
Key::AltDown => "Alt-Down",
Key::AltShiftDown => "Alt-Shift-Down",
Key::CtrlDown => "Ctrl-Down",
Key::CtrlShiftDown => "Ctrl-Shift-Down",
Key::CtrlAltDown => "Ctrl-Alt-Down",
Key::Up => "Up",
Key::ShiftUp => "Shift-Up",
Key::AltUp => "Alt-Up",
Key::AltShiftUp => "Alt-Shift-Up",
Key::CtrlUp => "Ctrl-Up",
Key::CtrlShiftUp => "Ctrl-Shift-Up",
Key::CtrlAltUp => "Ctrl-Alt-Up",
Key::Del => "Del",
Key::ShiftDel => "Shift-Del", Key::ShiftDel => "Shift-Del",
Key::AltDel => "Alt-Del",
Key::AltShiftDel => "Alt-Shift-Del",
Key::CtrlDel => "Ctrl-Del", Key::CtrlDel => "Ctrl-Del",
Key::CtrlShiftDel => "Ctrl-Shift-Del", Key::CtrlShiftDel => "Ctrl-Shift-Del",
Key::CtrlLeft => "Ctrl-Left",
Key::CtrlRight => "Ctrl-Right",
Key::CtrlUp => "Ctrl-Up",
Key::CtrlDown => "Ctrl-Down",
Key::CtrlPageUp => "Ctrl-PageUp",
Key::CtrlPageDown => "Ctrl-PageDown",
Key::PageUp => "PageUp",
Key::PageDown => "PageDown",
Key::Home => "Home", Key::Home => "Home",
Key::ShiftHome => "Shift-Home", Key::ShiftHome => "Shift-Home",
Key::AltHome => "Alt-Home",
Key::AltShiftHome => "Alt-Shift-Home",
Key::CtrlHome => "Ctrl-Home", Key::CtrlHome => "Ctrl-Home",
Key::CtrlShiftHome => "Ctrl-Shift-Home", Key::CtrlShiftHome => "Ctrl-Shift-Home",
Key::CtrlAltHome => "Ctrl-Alt-Home",
Key::End => "End", Key::End => "End",
Key::ShiftEnd => "Shift-End", Key::ShiftEnd => "Shift-End",
Key::AltEnd => "Alt-End",
Key::AltShiftEnd => "Alt-Shift-End",
Key::CtrlEnd => "Ctrl-End", Key::CtrlEnd => "Ctrl-End",
Key::CtrlShiftEnd => "Ctrl-Shift-End", Key::CtrlShiftEnd => "Ctrl-Shift-End",
Key::Backspace => "Backspace", Key::CtrlAltEnd => "Ctrl-Alt-End",
Key::Del => "Del",
Key::Enter => "Enter",
Key::ShiftTab => "Shift-Tab",
Key::Tab => "Tab",
Key::Ins => "Ins", Key::Ins => "Ins",
Key::AltIns => "Alt-Ins",
Key::CtrlIns => "Ctrl-Ins", Key::CtrlIns => "Ctrl-Ins",
Key::CtrlAltIns => "Ctrl-Alt-Ins",
Key::Esc => "Esc", Key::Esc => "Esc",
_ => "Missing key label", _ => "Missing key label",
}) })