3
0

setkeycodes.c 1.5 KB

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