From c6bb78bf30f17aeac45e4bf9ea7eb1856fb5cdb7 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 6 Aug 2021 15:02:01 +0100 Subject: win32: improved keycode detection In read_keys(): - Identify all keys on the numeric pad used to enter character codes. Otherwise Alt-Left/Alt-Right on the numeric pad are treated as word movements in command line editing, preventing the entry of character codes containing 4 or 6. - Add modifier flag bits to the virtual keycodes we care about. This means, for example, that only the unmodified Up/Down arrow keys move through shell history, not Up/Down plus arbitrary modifiers. --- win32/termios.c | 75 +++++++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/win32/termios.c b/win32/termios.c index 3a381903c..45d4e7740 100644 --- a/win32/termios.c +++ b/win32/termios.c @@ -49,55 +49,46 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) #else if (!record.Event.KeyEvent.uChar.AsciiChar) { #endif - if (alt_pressed) { + if (alt_pressed && !(state & ENHANCED_KEY)) { + /* keys on numeric pad used to enter character codes */ switch (record.Event.KeyEvent.wVirtualKeyCode) { - case VK_MENU: - case VK_INSERT: - case VK_END: - case VK_DOWN: - case VK_NEXT: - case VK_CLEAR: - case VK_HOME: - case VK_UP: - case VK_PRIOR: - case VK_KANA: + case VK_NUMPAD0: case VK_INSERT: + case VK_NUMPAD1: case VK_END: + case VK_NUMPAD2: case VK_DOWN: + case VK_NUMPAD3: case VK_NEXT: + case VK_NUMPAD4: case VK_LEFT: + case VK_NUMPAD5: case VK_CLEAR: + case VK_NUMPAD6: case VK_RIGHT: + case VK_NUMPAD7: case VK_HOME: + case VK_NUMPAD8: case VK_UP: + case VK_NUMPAD9: case VK_PRIOR: continue; } } switch (record.Event.KeyEvent.wVirtualKeyCode) { - case VK_DELETE: ret = KEYCODE_DELETE; goto done; - case VK_INSERT: ret = KEYCODE_INSERT; goto done; - case VK_UP: ret = KEYCODE_UP; goto done; - case VK_DOWN: ret = KEYCODE_DOWN; goto done; - case VK_RIGHT: - if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) { - ret = KEYCODE_CTRL_RIGHT; - goto done; - } - if (state & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) { - ret = KEYCODE_ALT_RIGHT; - goto done; - } - ret = KEYCODE_RIGHT; - goto done; - case VK_LEFT: - if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) { - ret = KEYCODE_CTRL_LEFT; - goto done; - } - if (state & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) { - ret = KEYCODE_ALT_LEFT; - goto done; - } - ret = KEYCODE_LEFT; - goto done; - case VK_HOME: ret = KEYCODE_HOME; goto done; - case VK_END: ret = KEYCODE_END; goto done; - case VK_PRIOR: ret = KEYCODE_PAGEUP; goto done; - case VK_NEXT: ret = KEYCODE_PAGEDOWN; goto done; + case VK_DELETE: ret = KEYCODE_DELETE; break; + case VK_INSERT: ret = KEYCODE_INSERT; break; + case VK_UP: ret = KEYCODE_UP; break; + case VK_DOWN: ret = KEYCODE_DOWN; break; + case VK_RIGHT: ret = KEYCODE_RIGHT; break; + case VK_LEFT: ret = KEYCODE_LEFT; break; + case VK_HOME: ret = KEYCODE_HOME; break; + case VK_END: ret = KEYCODE_END; break; + case VK_PRIOR: ret = KEYCODE_PAGEUP; break; + case VK_NEXT: ret = KEYCODE_PAGEDOWN; break; + default: + alt_pressed = FALSE; + continue; } - continue; + + if (state & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) + ret &= ~0x20; + if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) + ret &= ~0x40; + if (state & SHIFT_PRESSED) + ret &= ~0x80; + goto done; } #if ENABLE_FEATURE_EURO uchar = record.Event.KeyEvent.uChar.UnicodeChar; -- cgit v1.2.3-55-g6feb