blob: efb6e658fd4df49ba39a92024d9bbaeecb22515e [file] [log] [blame]
Erik Andersenabc199e2000-04-28 01:26:31 +00001/* vi: set sw=4 ts=4: */
2/*
3 * setkeycodes
4 *
5 * Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl>
6 *
Eric Andersencb81e642003-07-14 21:21:08 +00007 * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org>
Erik Andersenabc199e2000-04-28 01:26:31 +00008 *
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 Andersenabc199e2000-04-28 01:26:31 +000025#include <stdio.h>
26#include <stdlib.h>
27#include <fcntl.h>
28#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000029#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000030
31
32/* From <linux/kd.h> */
33struct kbkeycode {
34 unsigned int scancode, keycode;
35};
Mark Whitley59ab0252001-01-23 22:30:04 +000036static const int KDSETKEYCODE = 0x4B4D; /* write kernel keycode table entry */
Eric Andersenbd22ed82000-07-08 18:55:24 +000037
Eric Andersenc7bda1c2004-03-15 08:29:22 +000038extern int
Erik Andersenabc199e2000-04-28 01:26:31 +000039setkeycodes_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) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000046 bb_show_usage();
Erik Andersenabc199e2000-04-28 01:26:31 +000047 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000048
Eric Andersenc38678d2002-09-16 06:22:25 +000049 fd = get_console_fd();
Erik Andersenabc199e2000-04-28 01:26:31 +000050
51 while (argc > 2) {
52 a.keycode = atoi(argv[2]);
53 a.scancode = sc = strtol(argv[1], &ep, 16);
54 if (*ep) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000055 bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]);
Erik Andersenabc199e2000-04-28 01:26:31 +000056 }
57 if (a.scancode > 127) {
58 a.scancode -= 0xe000;
59 a.scancode += 128;
60 }
61 if (a.scancode > 255 || a.keycode > 127) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000062 bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds");
Erik Andersenabc199e2000-04-28 01:26:31 +000063 }
64 if (ioctl(fd,KDSETKEYCODE,&a)) {
65 perror("KDSETKEYCODE");
Manuel Novoa III cad53642003-03-19 09:13:01 +000066 bb_error_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode);
Erik Andersenabc199e2000-04-28 01:26:31 +000067 }
68 argc -= 2;
69 argv += 2;
70 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000071 return EXIT_SUCCESS;
Erik Andersenabc199e2000-04-28 01:26:31 +000072}