blob: b6a9a32afc0a50627abc5e637fd49687483cdae3 [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 */
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000012
Eric Andersenbd22ed82000-07-08 18:55:24 +000013/* From <linux/kd.h> */
14struct kbkeycode {
Denis Vlasenko1d426652008-03-17 09:09:09 +000015 unsigned scancode, keycode;
Eric Andersenbd22ed82000-07-08 18:55:24 +000016};
Rob Landleybc68cd12006-03-10 19:22:06 +000017enum {
18 KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
19};
Eric Andersenbd22ed82000-07-08 18:55:24 +000020
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000021int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
22int setkeycodes_main(int argc, char **argv)
Erik Andersenabc199e2000-04-28 01:26:31 +000023{
Denys Vlasenko2e068e72010-05-19 17:15:54 +020024 int fd;
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000025 struct kbkeycode a;
Erik Andersenabc199e2000-04-28 01:26:31 +000026
Denis Vlasenko2afd5ab2008-08-05 23:32:27 +000027 if (!(argc & 1) /* if even */ || argc < 2) {
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000028 bb_show_usage();
Erik Andersenabc199e2000-04-28 01:26:31 +000029 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000030
Denis Vlasenko2afd5ab2008-08-05 23:32:27 +000031 fd = get_console_fd_or_die();
Erik Andersenabc199e2000-04-28 01:26:31 +000032
Denys Vlasenko2e068e72010-05-19 17:15:54 +020033 while (argv[1]) {
34 int sc = xstrtoul_range(argv[1], 16, 0, 0xe07f);
35 if (sc >= 0xe000) {
36 sc -= 0xe000;
37 sc += 0x0080;
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000038 }
Denys Vlasenko2e068e72010-05-19 17:15:54 +020039 a.scancode = sc;
40 a.keycode = xatou_range(argv[2], 0, 255);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000041 ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
Denis Vlasenko2afd5ab2008-08-05 23:32:27 +000042 "can't set SCANCODE %x to KEYCODE %d",
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000043 sc, a.keycode);
Denis Vlasenko8fafacd2006-09-09 13:23:04 +000044 argv += 2;
Erik Andersenabc199e2000-04-28 01:26:31 +000045 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000046 return EXIT_SUCCESS;
Erik Andersenabc199e2000-04-28 01:26:31 +000047}