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 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 29 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | /* From <linux/kd.h> */ |
| 33 | struct kbkeycode { |
| 34 | unsigned int scancode, keycode; |
| 35 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 36 | enum { |
| 37 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 38 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 39 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 40 | extern int |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 41 | setkeycodes_main(int argc, char** argv) |
| 42 | { |
| 43 | char *ep; |
| 44 | int fd, sc; |
| 45 | struct kbkeycode a; |
| 46 | |
| 47 | if (argc % 2 != 1 || argc < 2) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 48 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 49 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 50 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 51 | fd = get_console_fd(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 52 | |
| 53 | while (argc > 2) { |
| 54 | a.keycode = atoi(argv[2]); |
| 55 | a.scancode = sc = strtol(argv[1], &ep, 16); |
| 56 | if (*ep) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 57 | bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 58 | } |
| 59 | if (a.scancode > 127) { |
| 60 | a.scancode -= 0xe000; |
| 61 | a.scancode += 128; |
| 62 | } |
| 63 | if (a.scancode > 255 || a.keycode > 127) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 64 | bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds"); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 65 | } |
| 66 | if (ioctl(fd,KDSETKEYCODE,&a)) { |
| 67 | perror("KDSETKEYCODE"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 68 | bb_error_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 69 | } |
| 70 | argc -= 2; |
| 71 | argv += 2; |
| 72 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 73 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 74 | } |