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 | */ |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 11 | |
| 12 | //usage:#define setkeycodes_trivial_usage |
| 13 | //usage: "SCANCODE KEYCODE..." |
| 14 | //usage:#define setkeycodes_full_usage "\n\n" |
| 15 | //usage: "Set entries into the kernel's scancode-to-keycode map,\n" |
| 16 | //usage: "allowing unusual keyboards to generate usable keycodes.\n\n" |
| 17 | //usage: "SCANCODE may be either xx or e0xx (hexadecimal),\n" |
| 18 | //usage: "and KEYCODE is given in decimal." |
| 19 | //usage: |
| 20 | //usage:#define setkeycodes_example_usage |
| 21 | //usage: "$ setkeycodes e030 127\n" |
| 22 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 23 | #include "libbb.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 24 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 25 | /* From <linux/kd.h> */ |
| 26 | struct kbkeycode { |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 27 | unsigned scancode, keycode; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 28 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 29 | enum { |
| 30 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 31 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 32 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 33 | int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 34 | int setkeycodes_main(int argc, char **argv) |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 35 | { |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 36 | int fd; |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 37 | struct kbkeycode a; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 38 | |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 39 | if (!(argc & 1) /* if even */ || argc < 2) { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 40 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 41 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 42 | |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 43 | fd = get_console_fd_or_die(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 44 | |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 45 | while (argv[1]) { |
| 46 | int sc = xstrtoul_range(argv[1], 16, 0, 0xe07f); |
| 47 | if (sc >= 0xe000) { |
| 48 | sc -= 0xe000; |
| 49 | sc += 0x0080; |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 50 | } |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 51 | a.scancode = sc; |
| 52 | a.keycode = xatou_range(argv[2], 0, 255); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 53 | ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a, |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 54 | "can't set SCANCODE %x to KEYCODE %d", |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 55 | sc, a.keycode); |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 56 | argv += 2; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 57 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 58 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 59 | } |