blob: d825257869a39a6e4cb70fac347086318d01c82c [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 *
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00009 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Erik Andersenabc199e2000-04-28 01:26:31 +000010 */
11
Erik Andersenabc199e2000-04-28 01:26:31 +000012#include <stdio.h>
13#include <stdlib.h>
14#include <fcntl.h>
15#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000016#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000017
18
19/* From <linux/kd.h> */
20struct kbkeycode {
21 unsigned int scancode, keycode;
22};
Rob Landleybc68cd12006-03-10 19:22:06 +000023enum {
24 KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
25};
Eric Andersenbd22ed82000-07-08 18:55:24 +000026
Eric Andersenc7bda1c2004-03-15 08:29:22 +000027extern int
Erik Andersenabc199e2000-04-28 01:26:31 +000028setkeycodes_main(int argc, char** argv)
29{
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000030 int fd, sc;
31 struct kbkeycode a;
Erik Andersenabc199e2000-04-28 01:26:31 +000032
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000033 if (argc % 2 != 1 || argc < 2) {
34 bb_show_usage();
Erik Andersenabc199e2000-04-28 01:26:31 +000035 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000036
Eric Andersenc38678d2002-09-16 06:22:25 +000037 fd = get_console_fd();
Erik Andersenabc199e2000-04-28 01:26:31 +000038
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000039 while (argc > 2) {
Denis Vlasenko13858992006-10-08 12:49:22 +000040 a.keycode = xatoul_range(argv[2], 0, 127);
41 a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000042 if (a.scancode > 127) {
43 a.scancode -= 0xe000;
44 a.scancode += 128;
45 }
Denis Vlasenko13858992006-10-08 12:49:22 +000046 if (ioctl(fd, KDSETKEYCODE, &a)) {
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000047 bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode);
48 }
49 argc -= 2;
50 argv += 2;
Erik Andersenabc199e2000-04-28 01:26:31 +000051 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000052 return EXIT_SUCCESS;
Erik Andersenabc199e2000-04-28 01:26:31 +000053}