From 7874ca73b5cc8cfbf8a9151c34747aac4a1792f4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 26 Jan 2019 08:29:44 +0000 Subject: 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. --- win32/termios.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'win32') 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) DWORD nevent_out, mode; int ret = -1; char *s; + int alt_pressed = FALSE; + DWORD state; if (fd != 0) 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) } if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) goto done; - if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown) + + if (record.EventType != KEY_EVENT) continue; - if (!record.Event.KeyEvent.uChar.AsciiChar) { - DWORD state = record.Event.KeyEvent.dwControlKeyState; + state = record.Event.KeyEvent.dwControlKeyState; + if (!record.Event.KeyEvent.bKeyDown) { + /* ignore all key up events except Alt */ + if (alt_pressed && !(state & LEFT_ALT_PRESSED)) + alt_pressed = FALSE; + else + continue; + } + else { + alt_pressed = ((state & LEFT_ALT_PRESSED) != 0); + } + + if (!record.Event.KeyEvent.uChar.AsciiChar) { + if (alt_pressed) { + switch (record.Event.KeyEvent.wVirtualKeyCode) { + case VK_MENU: + case VK_INSERT: + case VK_END: + case VK_DOWN: + case VK_NEXT: + case VK_LEFT: + case VK_CLEAR: + case VK_RIGHT: + case VK_HOME: + case VK_UP: + case VK_PRIOR: + case VK_KANA: + continue; + } + } if (state & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED) && (record.Event.KeyEvent.wVirtualKeyCode >= 'A' && record.Event.KeyEvent.wVirtualKeyCode <= 'Z')) { -- cgit v1.2.3-55-g6feb