setkeycodes.c 1.0 KB

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