Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * setkeycodes |
| 4 | * |
| 5 | * Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl> |
| 6 | * |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 7 | * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org> |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 8 | * |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Denis Vlasenko | 9a7d38f | 2007-05-31 22:42:12 +0000 | [diff] [blame] | 12 | //#include <sys/ioctl.h> |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 13 | #include "libbb.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 14 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 15 | /* From <linux/kd.h> */ |
| 16 | struct kbkeycode { |
| 17 | unsigned int scancode, keycode; |
| 18 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 19 | enum { |
| 20 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 21 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 22 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 23 | int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 24 | int setkeycodes_main(int argc, char **argv) |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 25 | { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 26 | int fd, sc; |
| 27 | struct kbkeycode a; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 29 | if (argc % 2 != 1 || argc < 2) { |
| 30 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 31 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 32 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 33 | fd = get_console_fd(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 34 | |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 35 | while (argc > 2) { |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 36 | a.keycode = xatoul_range(argv[2], 0, 127); |
| 37 | a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255); |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 38 | if (a.scancode > 127) { |
| 39 | a.scancode -= 0xe000; |
| 40 | a.scancode += 128; |
| 41 | } |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 42 | ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a, |
| 43 | "failed to set SCANCODE %x to KEYCODE %d", |
| 44 | sc, a.keycode); |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 45 | argc -= 2; |
| 46 | argv += 2; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 47 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 48 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 49 | } |