3
0

setkeycodes.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //config:config SETKEYCODES
  12. //config: bool "setkeycodes (2.1 kb)"
  13. //config: default y
  14. //config: help
  15. //config: This program loads entries into the kernel's scancode-to-keycode
  16. //config: map, allowing unusual keyboards to generate usable keycodes.
  17. //applet:IF_SETKEYCODES(APPLET_NOEXEC(setkeycodes, setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP, setkeycodes))
  18. //kbuild:lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
  19. //usage:#define setkeycodes_trivial_usage
  20. //usage: "{ SCANCODE KEYCODE }..."
  21. //usage:#define setkeycodes_full_usage "\n\n"
  22. //usage: "Modify kernel's scancode-to-keycode map,\n"
  23. //usage: "allowing unusual keyboards to generate usable keycodes.\n\n"
  24. //usage: "SCANCODE is either xx or e0xx (hexadecimal), KEYCODE is decimal."
  25. //usage:
  26. //usage:#define setkeycodes_example_usage
  27. //usage: "$ setkeycodes e030 127\n"
  28. #include "libbb.h"
  29. /* From <linux/kd.h> */
  30. struct kbkeycode {
  31. unsigned scancode, keycode;
  32. };
  33. enum {
  34. KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
  35. };
  36. int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  37. int setkeycodes_main(int argc, char **argv)
  38. {
  39. int fd;
  40. if (!(argc & 1) /* if even */ || argc < 2) {
  41. bb_show_usage();
  42. }
  43. fd = get_console_fd_or_die();
  44. while (argv[1]) {
  45. struct kbkeycode a;
  46. int sc;
  47. sc = xstrtoul_range(argv[1], 16, 0, 0xe07f);
  48. if (sc >= 0xe000) {
  49. sc -= 0xe000;
  50. sc += 0x0080;
  51. }
  52. a.scancode = sc;
  53. a.keycode = xatou_range(argv[2], 0, 255);
  54. ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
  55. "can't set SCANCODE %x to KEYCODE %d",
  56. sc, a.keycode);
  57. argv += 2;
  58. }
  59. return EXIT_SUCCESS;
  60. }