diff --git a/src/agent/ConsoleInput.cc b/src/agent/ConsoleInput.cc index 3dda67c..20f116c 100644 --- a/src/agent/ConsoleInput.cc +++ b/src/agent/ConsoleInput.cc @@ -39,6 +39,7 @@ #include "UnicodeEncoding.h" #include "Win32Console.h" +// MAPVK_VK_TO_VSC isn't defined by the old MinGW. #ifndef MAPVK_VK_TO_VSC #define MAPVK_VK_TO_VSC 0 #endif @@ -596,6 +597,7 @@ void ConsoleInput::appendKeyPress(std::vector &records, const bool ctrl = (keyState & LEFT_CTRL_PRESSED) != 0; const bool alt = (keyState & LEFT_ALT_PRESSED) != 0; const bool shift = (keyState & SHIFT_PRESSED) != 0; + const bool enhanced = (keyState & ENHANCED_KEY) != 0; bool hasDebugInput = false; if (isTracingEnabled()) { @@ -642,6 +644,9 @@ void ConsoleInput::appendKeyPress(std::vector &records, stepKeyState |= SHIFT_PRESSED; appendInputRecord(records, TRUE, VK_SHIFT, 0, stepKeyState); } + if (enhanced) { + stepKeyState |= ENHANCED_KEY; + } if (m_escapeInputEnabled) { reencodeEscapedKeyPress(records, virtualKey, codePoint, stepKeyState); } else { @@ -658,6 +663,9 @@ void ConsoleInput::appendKeyPress(std::vector &records, codePoint = 0; } appendCPInputRecords(records, FALSE, virtualKey, codePoint, stepKeyState); + if (enhanced) { + stepKeyState &= ~ENHANCED_KEY; + } if (shift) { stepKeyState &= ~SHIFT_PRESSED; appendInputRecord(records, FALSE, VK_SHIFT, 0, stepKeyState); diff --git a/src/agent/DefaultInputMap.cc b/src/agent/DefaultInputMap.cc index 186e324..b4dd7b4 100644 --- a/src/agent/DefaultInputMap.cc +++ b/src/agent/DefaultInputMap.cc @@ -206,6 +206,24 @@ const int kCsiShiftModifier = 1; const int kCsiAltModifier = 2; const int kCsiCtrlModifier = 4; +static inline bool useEnhancedForVirtualKey(uint16_t vk) { + switch (vk) { + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + case VK_INSERT: + case VK_DELETE: + case VK_HOME: + case VK_END: + case VK_PRIOR: + case VK_NEXT: + return true; + default: + return false; + } +} + static void addSimpleEntries(InputMap &inputMap) { struct SimpleEncoding { const char *encoding; @@ -233,9 +251,13 @@ static void addSimpleEntries(InputMap &inputMap) { }; for (size_t i = 0; i < DIM(simpleEncodings); ++i) { + auto k = simpleEncodings[i].key; + if (useEnhancedForVirtualKey(k.virtualKey)) { + k.keyState |= ENHANCED_KEY; + } inputMap.set(simpleEncodings[i].encoding, strlen(simpleEncodings[i].encoding), - simpleEncodings[i].key); + k); } } @@ -263,6 +285,9 @@ static inline void setEncoding(const ExpandContext &ctx, char *end, break; } } + if (useEnhancedForVirtualKey(k.virtualKey)) { + k.keyState |= ENHANCED_KEY; + } ctx.inputMap.set(ctx.buffer, end - ctx.buffer, k); }