1 /* vi: set sw=4 ts=4: */
3 * Mini kbd_mode implementation for busybox
5 * Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com>
6 * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
7 * console-utils v0.2.3, licensed under GNU GPLv2
9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 //usage:#define kbd_mode_trivial_usage
13 //usage: "[-a|k|s|u] [-C TTY]"
14 //usage:#define kbd_mode_full_usage "\n\n"
15 //usage: "Report or set the keyboard mode\n"
17 //usage: "\n -a Default (ASCII)"
18 //usage: "\n -k Medium-raw (keyboard)"
19 //usage: "\n -s Raw (scancode)"
20 //usage: "\n -u Unicode (utf-8)"
21 //usage: "\n -C TTY Affect TTY instead of /dev/tty"
26 int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
27 int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
37 const char *tty_name = CURRENT_TTY;
39 opt = getopt32(argv, "sakuC:", &tty_name);
40 fd = xopen_nonblocking(tty_name);
41 opt &= 0xf; /* clear -C bit, see (*) */
43 if (!opt) { /* print current setting */
44 const char *mode = "unknown";
47 xioctl(fd, KDGKBMODE, &m);
49 mode = "raw (scancode)";
50 else if (m == K_XLATE)
51 mode = "default (ASCII)";
52 else if (m == K_MEDIUMRAW)
53 mode = "mediumraw (keycode)";
54 else if (m == K_UNICODE)
55 mode = "Unicode (UTF-8)";
56 printf("The keyboard is in %s mode\n", mode);
58 /* here we depend on specific bits assigned to options (*) */
59 opt = opt & UNICODE ? 3 : opt >> 1;
60 /* double cast prevents warnings about widening conversion */
61 xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
64 if (ENABLE_FEATURE_CLEAN_UP)