diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/termios.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/win32/termios.c b/win32/termios.c index 7115bc0da..7a107c5bd 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -7,6 +7,8 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
7 | DWORD nevent_out, mode; | 7 | DWORD nevent_out, mode; |
8 | int ret = -1; | 8 | int ret = -1; |
9 | char *s; | 9 | char *s; |
10 | int alt_pressed = FALSE; | ||
11 | DWORD state; | ||
10 | 12 | ||
11 | if (fd != 0) | 13 | if (fd != 0) |
12 | bb_error_msg_and_die("read_key only works on stdin"); | 14 | bb_error_msg_and_die("read_key only works on stdin"); |
@@ -22,11 +24,40 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | |||
22 | } | 24 | } |
23 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) | 25 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) |
24 | goto done; | 26 | goto done; |
25 | if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown) | 27 | |
28 | if (record.EventType != KEY_EVENT) | ||
26 | continue; | 29 | continue; |
27 | if (!record.Event.KeyEvent.uChar.AsciiChar) { | ||
28 | DWORD state = record.Event.KeyEvent.dwControlKeyState; | ||
29 | 30 | ||
31 | state = record.Event.KeyEvent.dwControlKeyState; | ||
32 | if (!record.Event.KeyEvent.bKeyDown) { | ||
33 | /* ignore all key up events except Alt */ | ||
34 | if (alt_pressed && !(state & LEFT_ALT_PRESSED)) | ||
35 | alt_pressed = FALSE; | ||
36 | else | ||
37 | continue; | ||
38 | } | ||
39 | else { | ||
40 | alt_pressed = ((state & LEFT_ALT_PRESSED) != 0); | ||
41 | } | ||
42 | |||
43 | if (!record.Event.KeyEvent.uChar.AsciiChar) { | ||
44 | if (alt_pressed) { | ||
45 | switch (record.Event.KeyEvent.wVirtualKeyCode) { | ||
46 | case VK_MENU: | ||
47 | case VK_INSERT: | ||
48 | case VK_END: | ||
49 | case VK_DOWN: | ||
50 | case VK_NEXT: | ||
51 | case VK_LEFT: | ||
52 | case VK_CLEAR: | ||
53 | case VK_RIGHT: | ||
54 | case VK_HOME: | ||
55 | case VK_UP: | ||
56 | case VK_PRIOR: | ||
57 | case VK_KANA: | ||
58 | continue; | ||
59 | } | ||
60 | } | ||
30 | if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) && | 61 | if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) && |
31 | (record.Event.KeyEvent.wVirtualKeyCode >= 'A' && | 62 | (record.Event.KeyEvent.wVirtualKeyCode >= 'A' && |
32 | record.Event.KeyEvent.wVirtualKeyCode <= 'Z')) { | 63 | record.Event.KeyEvent.wVirtualKeyCode <= 'Z')) { |