diff options
| author | Ron Yorston <rmy@pobox.com> | 2021-08-06 15:02:01 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2021-08-06 15:12:11 +0100 |
| commit | c6bb78bf30f17aeac45e4bf9ea7eb1856fb5cdb7 (patch) | |
| tree | 08212d7b153c4f3be1b2effe7b511cbe07d27405 | |
| parent | 94c7e5f7b7bb24621a192c92e1ce961330988121 (diff) | |
| download | busybox-w32-c6bb78bf30f17aeac45e4bf9ea7eb1856fb5cdb7.tar.gz busybox-w32-c6bb78bf30f17aeac45e4bf9ea7eb1856fb5cdb7.tar.bz2 busybox-w32-c6bb78bf30f17aeac45e4bf9ea7eb1856fb5cdb7.zip | |
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.
| -rw-r--r-- | win32/termios.c | 75 |
1 files 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) | |||
| 49 | #else | 49 | #else |
| 50 | if (!record.Event.KeyEvent.uChar.AsciiChar) { | 50 | if (!record.Event.KeyEvent.uChar.AsciiChar) { |
| 51 | #endif | 51 | #endif |
| 52 | if (alt_pressed) { | 52 | if (alt_pressed && !(state & ENHANCED_KEY)) { |
| 53 | /* keys on numeric pad used to enter character codes */ | ||
| 53 | switch (record.Event.KeyEvent.wVirtualKeyCode) { | 54 | switch (record.Event.KeyEvent.wVirtualKeyCode) { |
| 54 | case VK_MENU: | 55 | case VK_NUMPAD0: case VK_INSERT: |
| 55 | case VK_INSERT: | 56 | case VK_NUMPAD1: case VK_END: |
| 56 | case VK_END: | 57 | case VK_NUMPAD2: case VK_DOWN: |
| 57 | case VK_DOWN: | 58 | case VK_NUMPAD3: case VK_NEXT: |
| 58 | case VK_NEXT: | 59 | case VK_NUMPAD4: case VK_LEFT: |
| 59 | case VK_CLEAR: | 60 | case VK_NUMPAD5: case VK_CLEAR: |
| 60 | case VK_HOME: | 61 | case VK_NUMPAD6: case VK_RIGHT: |
| 61 | case VK_UP: | 62 | case VK_NUMPAD7: case VK_HOME: |
| 62 | case VK_PRIOR: | 63 | case VK_NUMPAD8: case VK_UP: |
| 63 | case VK_KANA: | 64 | case VK_NUMPAD9: case VK_PRIOR: |
| 64 | continue; | 65 | continue; |
| 65 | } | 66 | } |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | switch (record.Event.KeyEvent.wVirtualKeyCode) { | 69 | switch (record.Event.KeyEvent.wVirtualKeyCode) { |
| 69 | case VK_DELETE: ret = KEYCODE_DELETE; goto done; | 70 | case VK_DELETE: ret = KEYCODE_DELETE; break; |
| 70 | case VK_INSERT: ret = KEYCODE_INSERT; goto done; | 71 | case VK_INSERT: ret = KEYCODE_INSERT; break; |
| 71 | case VK_UP: ret = KEYCODE_UP; goto done; | 72 | case VK_UP: ret = KEYCODE_UP; break; |
| 72 | case VK_DOWN: ret = KEYCODE_DOWN; goto done; | 73 | case VK_DOWN: ret = KEYCODE_DOWN; break; |
| 73 | case VK_RIGHT: | 74 | case VK_RIGHT: ret = KEYCODE_RIGHT; break; |
| 74 | if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) { | 75 | case VK_LEFT: ret = KEYCODE_LEFT; break; |
| 75 | ret = KEYCODE_CTRL_RIGHT; | 76 | case VK_HOME: ret = KEYCODE_HOME; break; |
| 76 | goto done; | 77 | case VK_END: ret = KEYCODE_END; break; |
| 77 | } | 78 | case VK_PRIOR: ret = KEYCODE_PAGEUP; break; |
| 78 | if (state & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) { | 79 | case VK_NEXT: ret = KEYCODE_PAGEDOWN; break; |
| 79 | ret = KEYCODE_ALT_RIGHT; | 80 | default: |
| 80 | goto done; | 81 | alt_pressed = FALSE; |
| 81 | } | 82 | continue; |
| 82 | ret = KEYCODE_RIGHT; | ||
| 83 | goto done; | ||
| 84 | case VK_LEFT: | ||
| 85 | if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) { | ||
| 86 | ret = KEYCODE_CTRL_LEFT; | ||
| 87 | goto done; | ||
| 88 | } | ||
| 89 | if (state & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) { | ||
| 90 | ret = KEYCODE_ALT_LEFT; | ||
| 91 | goto done; | ||
| 92 | } | ||
| 93 | ret = KEYCODE_LEFT; | ||
| 94 | goto done; | ||
| 95 | case VK_HOME: ret = KEYCODE_HOME; goto done; | ||
| 96 | case VK_END: ret = KEYCODE_END; goto done; | ||
| 97 | case VK_PRIOR: ret = KEYCODE_PAGEUP; goto done; | ||
| 98 | case VK_NEXT: ret = KEYCODE_PAGEDOWN; goto done; | ||
| 99 | } | 83 | } |
| 100 | continue; | 84 | |
| 85 | if (state & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) | ||
| 86 | ret &= ~0x20; | ||
| 87 | if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) | ||
| 88 | ret &= ~0x40; | ||
| 89 | if (state & SHIFT_PRESSED) | ||
| 90 | ret &= ~0x80; | ||
| 91 | goto done; | ||
| 101 | } | 92 | } |
| 102 | #if ENABLE_FEATURE_EURO | 93 | #if ENABLE_FEATURE_EURO |
| 103 | uchar = record.Event.KeyEvent.uChar.UnicodeChar; | 94 | uchar = record.Event.KeyEvent.uChar.UnicodeChar; |
