blob: e9a050862b9187c72f74cafc35d54185b4429f37 [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
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000012//#include <sys/ioctl.h>
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000013#include "libbb.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000014
Eric Andersenbd22ed82000-07-08 18:55:24 +000015/* From <linux/kd.h> */
16struct kbkeycode {
Denis Vlasenko1d426652008-03-17 09:09:09 +000017 unsigned scancode, keycode;
Eric Andersenbd22ed82000-07-08 18:55:24 +000018};
Rob Landleybc68cd12006-03-10 19:22:06 +000019enum {
20 KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
21};
Eric Andersenbd22ed82000-07-08 18:55:24 +000022
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000023int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
24int setkeycodes_main(int argc, char **argv)
Erik Andersenabc199e2000-04-28 01:26:31 +000025{
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000026 int fd, sc;
27 struct kbkeycode a;
Erik Andersenabc199e2000-04-28 01:26:31 +000028
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000029 if (argc % 2 != 1 || argc < 2) {
30 bb_show_usage();
Erik Andersenabc199e2000-04-28 01:26:31 +000031 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000032
Eric Andersenc38678d2002-09-16 06:22:25 +000033 fd = get_console_fd();
Erik Andersenabc199e2000-04-28 01:26:31 +000034
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000035 while (argc > 2) {
Denis Vlasenko1d426652008-03-17 09:09:09 +000036 a.keycode = xatou_range(argv[2], 0, 127);
Denis Vlasenko13858992006-10-08 12:49:22 +000037 a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000038 if (a.scancode > 127) {
39 a.scancode -= 0xe000;
40 a.scancode += 128;
41 }
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000042 ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
43 "failed to set SCANCODE %x to KEYCODE %d",
44 sc, a.keycode);
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000045 argc -= 2;
46 argv += 2;
Erik Andersenabc199e2000-04-28 01:26:31 +000047 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000048 return EXIT_SUCCESS;
Erik Andersenabc199e2000-04-28 01:26:31 +000049}