From 943d73458f3b8b9ac8c1a519859bec69a198e05d Mon Sep 17 00:00:00 2001 From: sigmaSd Date: Mon, 3 Jun 2019 08:32:33 +0100 Subject: [PATCH] Add Ctrl/Shift + Arrow support (#147) --- crossterm_input/src/input/input.rs | 12 +++++++++++- crossterm_input/src/input/mod.rs | 8 ++++++++ crossterm_input/src/input/windows_input.rs | 9 +++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crossterm_input/src/input/input.rs b/crossterm_input/src/input/input.rs index 9731f1e..6829a92 100644 --- a/crossterm_input/src/input/input.rs +++ b/crossterm_input/src/input/input.rs @@ -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, diff --git a/crossterm_input/src/input/mod.rs b/crossterm_input/src/input/mod.rs index 0cfd570..5080641 100644 --- a/crossterm_input/src/input/mod.rs +++ b/crossterm_input/src/input/mod.rs @@ -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. diff --git a/crossterm_input/src/input/windows_input.rs b/crossterm_input/src/input/windows_input.rs index 06c028d..da687a6 100644 --- a/crossterm_input/src/input/windows_input.rs +++ b/crossterm_input/src/input/windows_input.rs @@ -224,6 +224,15 @@ fn handle_key_event(key_event: &KeyEventRecord, seq: &mut Vec) { 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 => {