2 * call: setkeycode scancode keycode ...
3 * (where scancode is either xx or e0xx, given in hexadecimal,
4 * and keycode is given in decimal)
6 * aeb, 941108, 2004-01-11
11 #include <sys/ioctl.h>
17 static void __attribute__ ((noreturn))
19 fprintf(stderr, "setkeycode: %s\n", s);
21 "usage: setkeycode scancode keycode ...\n"
22 " (where scancode is either xx or e0xx, given in hexadecimal,\n"
23 " and keycode is given in decimal)\n"));
28 main(int argc, char **argv) {
33 set_progname(argv[0]);
35 setlocale(LC_ALL, "");
36 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
37 textdomain(PACKAGE_NAME);
39 if (argc == 2 && !strcmp(argv[1], "-V"))
40 print_version_and_exit();
43 usage(_("even number of arguments expected"));
47 a.keycode = atoi(argv[2]);
48 a.scancode = strtol(argv[1], &ep, 16);
50 usage(_("error reading scancode"));
51 if (a.scancode >= 0xe000) {
53 a.scancode += 128; /* some kernels needed +256 */
56 /* Test is OK up to 2.5.31--later kernels have more keycodes */
57 if (a.scancode > 255 || a.keycode > 127)
58 usage(_("code outside bounds"));
60 /* Both fields are unsigned int, so can be large;
61 for current kernels the correct test might be
62 (a.scancode > 255 || a.keycode > 239)
63 but we can leave testing to the kernel. */
65 if (ioctl(fd,KDSETKEYCODE,&a)) {
66 perror("KDSETKEYCODE");
68 _("failed to set scancode %x to keycode %d\n"),
69 a.scancode, a.keycode);