setkeycodes.c 1.0 KB

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 tarball for details.
  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, sc;
  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 (argc > 2) {
  29. a.keycode = xatou_range(argv[2], 0, 127);
  30. a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
  31. if (a.scancode > 127) {
  32. a.scancode -= 0xe000;
  33. a.scancode += 128;
  34. }
  35. ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
  36. "can't set SCANCODE %x to KEYCODE %d",
  37. sc, a.keycode);
  38. argc -= 2;
  39. argv += 2;
  40. }
  41. return EXIT_SUCCESS;
  42. }