Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/console-tools/showkey.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/console-tools/showkey.c
r2725 r3232 7 7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define showkey_trivial_usage 11 //usage: "[-a | -k | -s]" 12 //usage:#define showkey_full_usage "\n\n" 13 //usage: "Show keys pressed\n" 14 //usage: "\n -a Display decimal/octal/hex values of the keys" 15 //usage: "\n -k Display interpreted keycodes (default)" 16 //usage: "\n -s Display raw scan-codes" 9 17 10 18 #include "libbb.h" … … 57 65 getopt32(argv, "aks"); 58 66 59 // get keyboard settings60 xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);61 printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n",62 kbmode == K_RAW ? "RAW" :63 (kbmode == K_XLATE ? "XLATE" :64 (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :65 (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN")))66 , (option_mask32 & OPT_a) ? "on EOF (ctrl-D)" : "10s after last keypress"67 );68 69 67 // prepare for raw mode 70 68 xget1(&tio, &tio0); … … 72 70 xset1(&tio); 73 71 72 #define press_keys "Press any keys, program terminates %s:\r\n\n" 73 74 74 if (option_mask32 & OPT_a) { 75 // just read stdin char by char 75 76 unsigned char c; 76 77 77 // just read stdin char by char 78 printf(press_keys, "on EOF (ctrl-D)"); 79 80 // read and show byte values 78 81 while (1 == read(STDIN_FILENO, &c, 1)) { 79 82 printf("%3u 0%03o 0x%02x\r\n", c, c, c); … … 81 84 break; 82 85 } 86 83 87 } else { 88 // we assume a PC keyboard 89 xioctl(STDIN_FILENO, KDGKBMODE, &kbmode); 90 printf("Keyboard mode was %s.\r\n\n", 91 kbmode == K_RAW ? "RAW" : 92 (kbmode == K_XLATE ? "XLATE" : 93 (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" : 94 (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN"))) 95 ); 96 84 97 // set raw keyboard mode 85 98 xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW)); … … 87 100 // we should exit on any signal; signals should interrupt read 88 101 bb_signals_recursive_norestart(BB_FATAL_SIGS, record_signo); 102 103 // inform user that program ends after time of inactivity 104 printf(press_keys, "10s after last keypress"); 89 105 90 106 // read and show scancodes … … 95 111 // setup 10s watchdog 96 112 alarm(10); 113 97 114 // read scancodes 98 115 n = read(STDIN_FILENO, buf, sizeof(buf)); … … 122 139 puts("\r"); 123 140 } 141 142 // restore keyboard mode 143 xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode); 124 144 } 125 145 126 // restore keyboard andconsole settings146 // restore console settings 127 147 xset1(&tio0); 128 xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);129 148 130 149 return EXIT_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.