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 | |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 16 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | /* From <linux/kd.h> */ |
| 20 | struct kbkeycode { |
| 21 | unsigned int scancode, keycode; |
| 22 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 23 | enum { |
| 24 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 25 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 26 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 27 | extern int |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 28 | setkeycodes_main(int argc, char** argv) |
| 29 | { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 30 | int fd, sc; |
| 31 | struct kbkeycode a; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 32 | |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 33 | if (argc % 2 != 1 || argc < 2) { |
| 34 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 35 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 36 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 37 | fd = get_console_fd(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 38 | |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 39 | while (argc > 2) { |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 40 | a.keycode = xatoul_range(argv[2], 0, 127); |
| 41 | a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255); |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 42 | if (a.scancode > 127) { |
| 43 | a.scancode -= 0xe000; |
| 44 | a.scancode += 128; |
| 45 | } |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 46 | if (ioctl(fd, KDSETKEYCODE, &a)) { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 47 | bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); |
| 48 | } |
| 49 | argc -= 2; |
| 50 | argv += 2; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 51 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 52 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 53 | } |