1 Pull patch from BusyBox' git repo to make "showkey -a" work on any stdin
2 Source: http://git.busybox.net/busybox/commit/?id=9beb68e3e2dc1c6f457acfb307cfed73cce65cd9
5 --- a/console-tools/showkey.c
6 +++ b/console-tools/showkey.c
7 @@ -56,37 +56,45 @@ int showkey_main(int argc UNUSED_PARAM,
8 // FIXME: aks are all mutually exclusive
11 - // get keyboard settings
12 - xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
13 - printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n",
14 - kbmode == K_RAW ? "RAW" :
15 - (kbmode == K_XLATE ? "XLATE" :
16 - (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
17 - (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN")))
18 - , (option_mask32 & OPT_a) ? "on EOF (ctrl-D)" : "10s after last keypress"
21 // prepare for raw mode
23 // put stdin in raw mode
26 +#define press_keys "Press any keys, program terminates %s:\r\n\n"
28 if (option_mask32 & OPT_a) {
29 + // just read stdin char by char
32 - // just read stdin char by char
33 + printf(press_keys, "on EOF (ctrl-D)");
35 + // read and show byte values
36 while (1 == read(STDIN_FILENO, &c, 1)) {
37 printf("%3u 0%03o 0x%02x\r\n", c, c, c);
38 if (04 /*CTRL-D*/ == c)
43 + // we assume a PC keyboard
44 + xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
45 + printf("Keyboard mode was %s.\r\n\n",
46 + kbmode == K_RAW ? "RAW" :
47 + (kbmode == K_XLATE ? "XLATE" :
48 + (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
49 + (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN")))
52 // set raw keyboard mode
53 xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW));
55 // we should exit on any signal; signals should interrupt read
56 bb_signals_recursive_norestart(BB_FATAL_SIGS, record_signo);
58 + // inform user that program ends after time of inactivity
59 + printf(press_keys, "10s after last keypress");
61 // read and show scancodes
62 while (!bb_got_signal) {
64 @@ -94,6 +102,7 @@ int showkey_main(int argc UNUSED_PARAM,
70 n = read(STDIN_FILENO, buf, sizeof(buf));
72 @@ -121,11 +130,13 @@ int showkey_main(int argc UNUSED_PARAM,
77 + // restore keyboard mode
78 + xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);
81 - // restore keyboard and console settings
82 + // restore console settings
84 - xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);