Add Ctrl/Shift + Arrow support (#147)

This commit is contained in:
sigmaSd 2019-06-03 08:32:33 +01:00 committed by Timon
parent 4fca41d6c5
commit 943d73458f
3 changed files with 28 additions and 1 deletions

View File

@ -362,7 +362,17 @@ where
_ => InputEvent::Unknown,
}
}
_ => InputEvent::Unknown,
e => match (buf.last().unwrap(), e) {
(53, 65) => InputEvent::Keyboard(KeyEvent::CtrlUp),
(53, 66) => InputEvent::Keyboard(KeyEvent::CtrlDown),
(53, 67) => InputEvent::Keyboard(KeyEvent::CtrlRight),
(53, 68) => InputEvent::Keyboard(KeyEvent::CtrlLeft),
(50, 65) => InputEvent::Keyboard(KeyEvent::ShiftUp),
(50, 66) => InputEvent::Keyboard(KeyEvent::ShiftDown),
(50, 67) => InputEvent::Keyboard(KeyEvent::ShiftRight),
(50, 68) => InputEvent::Keyboard(KeyEvent::ShiftLeft),
_ => InputEvent::Unknown,
},
}
}
_ => InputEvent::Unknown,

View File

@ -111,6 +111,14 @@ pub enum KeyEvent {
Ctrl(char),
Null,
Esc,
CtrlUp,
CtrlDown,
CtrlRight,
CtrlLeft,
ShiftUp,
ShiftDown,
ShiftRight,
ShiftLeft,
}
/// This type allows you to read the input asynchronously which means that input events are gathered on the background and will be queued for you to read.

View File

@ -224,6 +224,15 @@ fn handle_key_event(key_event: &KeyEventRecord, seq: &mut Vec<u8>) {
VK_LEFT | VK_UP | VK_RIGHT | VK_DOWN => {
seq.push(b'\x1B');
seq.push(b'[');
// Modifier Keys (Ctrl, Shift) Support
let key_state = &key_event.control_key_state;
if key_state.has_state(RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) {
seq.push(53);
} else if key_state.has_state(SHIFT_PRESSED) {
seq.push(50);
}
seq.push([b'D', b'A', b'C', b'B'][(key_event.virtual_key_code - 0x25) as usize]);
}
VK_PRIOR | VK_NEXT => {