source: branches/3.2/mindi-busybox/console-tools/setkeycodes.c @ 3232

Last change on this file since 3232 was 3232, checked in by Bruno Cornec, 7 years ago
  • Update mindi-busybox to 1.21.1
File size: 1.5 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * setkeycodes
4 *
5 * Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl>
6 *
7 * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org>
8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 */
11
12//usage:#define setkeycodes_trivial_usage
13//usage:       "SCANCODE KEYCODE..."
14//usage:#define setkeycodes_full_usage "\n\n"
15//usage:       "Set entries into the kernel's scancode-to-keycode map,\n"
16//usage:       "allowing unusual keyboards to generate usable keycodes.\n\n"
17//usage:       "SCANCODE may be either xx or e0xx (hexadecimal),\n"
18//usage:       "and KEYCODE is given in decimal."
19//usage:
20//usage:#define setkeycodes_example_usage
21//usage:       "$ setkeycodes e030 127\n"
22
23#include "libbb.h"
24
25/* From <linux/kd.h> */
26struct kbkeycode {
27    unsigned scancode, keycode;
28};
29enum {
30    KDSETKEYCODE = 0x4B4D  /* write kernel keycode table entry */
31};
32
33int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34int setkeycodes_main(int argc, char **argv)
35{
36    int fd;
37    struct kbkeycode a;
38
39    if (!(argc & 1) /* if even */ || argc < 2) {
40        bb_show_usage();
41    }
42
43    fd = get_console_fd_or_die();
44
45    while (argv[1]) {
46        int sc = xstrtoul_range(argv[1], 16, 0, 0xe07f);
47        if (sc >= 0xe000) {
48            sc -= 0xe000;
49            sc += 0x0080;
50        }
51        a.scancode = sc;
52        a.keycode = xatou_range(argv[2], 0, 255);
53        ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
54            "can't set SCANCODE %x to KEYCODE %d",
55            sc, a.keycode);
56        argv += 2;
57    }
58    return EXIT_SUCCESS;
59}
Note: See TracBrowser for help on using the repository browser.