3
0

setkeycodes.c 1010 B

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