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 | * |
| 7 | * Adjusted for BusyBox by Erik Andersen <andersee@debian.org> |
| 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 | |
Eric Andersen | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 25 | #include "busybox.h" |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <sys/ioctl.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 | }; |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 36 | static const int KDSETKEYCODE = 0x4B4D; /* write kernel keycode table entry */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 37 | |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 38 | extern int |
| 39 | setkeycodes_main(int argc, char** argv) |
| 40 | { |
| 41 | char *ep; |
| 42 | int fd, sc; |
| 43 | struct kbkeycode a; |
| 44 | |
| 45 | if (argc % 2 != 1 || argc < 2) { |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame^] | 46 | show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | fd = get_console_fd("/dev/console"); |
| 50 | |
| 51 | while (argc > 2) { |
| 52 | a.keycode = atoi(argv[2]); |
| 53 | a.scancode = sc = strtol(argv[1], &ep, 16); |
| 54 | if (*ep) { |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 55 | error_msg_and_die("error reading SCANCODE: '%s'", argv[1]); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 56 | } |
| 57 | if (a.scancode > 127) { |
| 58 | a.scancode -= 0xe000; |
| 59 | a.scancode += 128; |
| 60 | } |
| 61 | if (a.scancode > 255 || a.keycode > 127) { |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 62 | error_msg_and_die("SCANCODE or KEYCODE outside bounds"); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 63 | } |
| 64 | if (ioctl(fd,KDSETKEYCODE,&a)) { |
| 65 | perror("KDSETKEYCODE"); |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 66 | 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] | 67 | } |
| 68 | argc -= 2; |
| 69 | argv += 2; |
| 70 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 71 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 72 | } |