aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-01-26 08:29:44 +0000
committerRon Yorston <rmy@pobox.com>2019-01-26 08:29:44 +0000
commit7874ca73b5cc8cfbf8a9151c34747aac4a1792f4 (patch)
treec3d5621a337ce72124d669d275ecba1c5fdf7d60 /win32
parent19f7732aedd89c5718da729e5f4c4056ce828a02 (diff)
downloadbusybox-w32-7874ca73b5cc8cfbf8a9151c34747aac4a1792f4.tar.gz
busybox-w32-7874ca73b5cc8cfbf8a9151c34747aac4a1792f4.tar.bz2
busybox-w32-7874ca73b5cc8cfbf8a9151c34747aac4a1792f4.zip
win32: allow characters to be entered as ALTNNN
It wasn't possible to enter characters using Alt and the decimal character code. This was because the character is generated when the Alt key is released but the WIN32 implementation of read_key() ignored all key up events. Modify read_key() to ignore numbers entered on the numeric keypad with Alt pressed and to detect when Alt is released. Fixes GitHub issue #136.
Diffstat (limited to 'win32')
-rw-r--r--win32/termios.c37
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')) {