diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 15:37:12 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 18:02:19 +1000 |
commit | 79fc61359a8f9a9563627e9ad8e5938c3ffee4ca (patch) | |
tree | 29b4cab2d31e18d630d8876a31c5d534491fbae8 /win32 | |
parent | 5531e51fe26e4c6bbd34dbaa98b12564f8a7f295 (diff) | |
download | busybox-w32-79fc61359a8f9a9563627e9ad8e5938c3ffee4ca.tar.gz busybox-w32-79fc61359a8f9a9563627e9ad8e5938c3ffee4ca.tar.bz2 busybox-w32-79fc61359a8f9a9563627e9ad8e5938c3ffee4ca.zip |
win32: read_key: reset console state after reading
Diffstat (limited to 'win32')
-rw-r--r-- | win32/termios.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/win32/termios.c b/win32/termios.c index 6d85ff98e..1bd3cbd5b 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -12,25 +12,29 @@ int tcgetattr(int fd UNUSED_PARAM, struct termios *t UNUSED_PARAM) | |||
12 | 12 | ||
13 | int64_t FAST_FUNC read_key(int fd, char *buf, int timeout UNUSED_PARAM) | 13 | int64_t FAST_FUNC read_key(int fd, char *buf, int timeout UNUSED_PARAM) |
14 | { | 14 | { |
15 | static int initialized = 0; | ||
16 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); | 15 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); |
17 | INPUT_RECORD record; | 16 | INPUT_RECORD record; |
18 | DWORD nevent_out; | 17 | DWORD nevent_out, mode; |
18 | int ret = -1; | ||
19 | 19 | ||
20 | if (fd != 0) | 20 | if (fd != 0) |
21 | bb_error_msg_and_die("read_key only works on stdin"); | 21 | bb_error_msg_and_die("read_key only works on stdin"); |
22 | if (cin == INVALID_HANDLE_VALUE) | 22 | if (cin == INVALID_HANDLE_VALUE) |
23 | return -1; | 23 | return -1; |
24 | if (!initialized) { | 24 | GetConsoleMode(cin, &mode); |
25 | SetConsoleMode(cin, ENABLE_ECHO_INPUT); | 25 | SetConsoleMode(cin, 0); |
26 | initialized = 1; | ||
27 | } | ||
28 | 26 | ||
29 | while (1) { | 27 | while (1) { |
30 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) | 28 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) |
31 | return -1; | 29 | goto done; |
32 | if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown) | 30 | if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown) |
33 | continue; | 31 | continue; |
34 | return record.Event.KeyEvent.uChar.AsciiChar; | 32 | if (!record.Event.KeyEvent.uChar.AsciiChar) |
33 | continue; | ||
34 | ret = record.Event.KeyEvent.uChar.AsciiChar; | ||
35 | break; | ||
35 | } | 36 | } |
37 | done: | ||
38 | SetConsoleMode(cin, mode); | ||
39 | return ret; | ||
36 | } | 40 | } |