setkeycodes.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 tarball for details.
  10. */
  11. //#include <sys/ioctl.h>
  12. #include "libbb.h"
  13. /* From <linux/kd.h> */
  14. struct kbkeycode {
  15. unsigned scancode, keycode;
  16. };
  17. enum {
  18. KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
  19. };
  20. int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  21. int setkeycodes_main(int argc, char **argv)
  22. {
  23. int fd, sc;
  24. struct kbkeycode a;
  25. if (argc % 2 != 1 || argc < 2) {
  26. bb_show_usage();
  27. }
  28. fd = get_console_fd();
  29. while (argc > 2) {
  30. a.keycode = xatou_range(argv[2], 0, 127);
  31. a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
  32. if (a.scancode > 127) {
  33. a.scancode -= 0xe000;
  34. a.scancode += 128;
  35. }
  36. ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
  37. "failed to set SCANCODE %x to KEYCODE %d",
  38. sc, a.keycode);
  39. argc -= 2;
  40. argv += 2;
  41. }
  42. return EXIT_SUCCESS;
  43. }