From a3789e9bb6b9c74b540ecf022f02cc185e507924 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 18 May 2017 04:20:36 -0500 Subject: [PATCH] Add an entry for Ctrl-C in DefaultInputMap's SimpleEncoding table Fixes https://github.com/rprichard/winpty/issues/116 --- src/agent/ConsoleInput.cc | 9 ++++++++- src/agent/DefaultInputMap.cc | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/agent/ConsoleInput.cc b/src/agent/ConsoleInput.cc index 497b1493..9a7549b3 100644 --- a/src/agent/ConsoleInput.cc +++ b/src/agent/ConsoleInput.cc @@ -375,7 +375,14 @@ int ConsoleInput::scanInput(std::vector &records, { ASSERT(inputSize >= 1); - // Ctrl-C. + // Ctrl-C. We need to use window messages when the console is in + // ENABLE_PROCESSED_INPUT mode so that Ctrl-C interrupts a ReadConsole + // call. In unprocessed mode, we can't use this code path, because it + // would produce a KEY_EVENT_RECORD with a NUL UnicodeChar. We can't use + // the ordinary VkKeyScan code path for Ctrl-C, either, because it produces + // an unmodified VK_CANCEL. Instead, there's an entry for Ctrl-C in the + // SimpleEncoding table in DefaultInputMap. + // See https://github.com/rprichard/winpty/issues/116. if (input[0] == '\x03' && (inputConsoleMode() & ENABLE_PROCESSED_INPUT)) { flushInputRecords(records); trace("Sending Ctrl-C KEYDOWN/KEYUP messages"); diff --git a/src/agent/DefaultInputMap.cc b/src/agent/DefaultInputMap.cc index b4dd7b42..e3a4dba1 100644 --- a/src/agent/DefaultInputMap.cc +++ b/src/agent/DefaultInputMap.cc @@ -235,6 +235,7 @@ static void addSimpleEntries(InputMap &inputMap) { { "\x7F", { VK_BACK, '\x08', 0, } }, { ESC "\x7F", { VK_BACK, '\x08', LEFT_ALT_PRESSED, } }, + { "\x03", { 'C', '\x03', LEFT_CTRL_PRESSED, } }, // Handle special F1-F5 for TERM=linux and TERM=cygwin. { ESC "[[A", { VK_F1, '\0', 0 } },