blob: 6d85ff98ec32e86598141d4901eb2a5a733e4229 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "libbb.h"
int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t UNUSED_PARAM)
{
return -1;
}
int tcgetattr(int fd UNUSED_PARAM, struct termios *t UNUSED_PARAM)
{
return -1;
}
int64_t FAST_FUNC read_key(int fd, char *buf, int timeout UNUSED_PARAM)
{
static int initialized = 0;
HANDLE cin = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD record;
DWORD nevent_out;
if (fd != 0)
bb_error_msg_and_die("read_key only works on stdin");
if (cin == INVALID_HANDLE_VALUE)
return -1;
if (!initialized) {
SetConsoleMode(cin, ENABLE_ECHO_INPUT);
initialized = 1;
}
while (1) {
if (!ReadConsoleInput(cin, &record, 1, &nevent_out))
return -1;
if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown)
continue;
return record.Event.KeyEvent.uChar.AsciiChar;
}
}
|