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 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 10 | */ |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 12 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 13 | /* From <linux/kd.h> */ |
| 14 | struct kbkeycode { |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 15 | unsigned scancode, keycode; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 16 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 17 | enum { |
| 18 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 19 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 20 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 21 | int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 22 | int setkeycodes_main(int argc, char **argv) |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 23 | { |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 24 | int fd; |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 25 | struct kbkeycode a; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 26 | |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 27 | if (!(argc & 1) /* if even */ || argc < 2) { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 28 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 29 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 30 | |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 31 | fd = get_console_fd_or_die(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 32 | |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 33 | while (argv[1]) { |
| 34 | int sc = xstrtoul_range(argv[1], 16, 0, 0xe07f); |
| 35 | if (sc >= 0xe000) { |
| 36 | sc -= 0xe000; |
| 37 | sc += 0x0080; |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 38 | } |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 39 | a.scancode = sc; |
| 40 | a.keycode = xatou_range(argv[2], 0, 255); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 41 | ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a, |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 42 | "can't set SCANCODE %x to KEYCODE %d", |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 43 | sc, a.keycode); |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 44 | argv += 2; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 45 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 46 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 47 | } |