sendevent.c 843 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* sendevent.c - Send Linux input events.
  2. *
  3. * Copyright 2016 The Android Open Source Project
  4. USE_SENDEVENT(NEWTOY(sendevent, "<4>4", TOYFLAG_USR|TOYFLAG_SBIN))
  5. config SENDEVENT
  6. bool "sendevent"
  7. default y
  8. depends on TOYBOX_ON_ANDROID
  9. help
  10. usage: sendevent DEVICE TYPE CODE VALUE
  11. Sends a Linux input event.
  12. */
  13. #define FOR_sendevent
  14. #include "toys.h"
  15. #include <linux/input.h>
  16. void sendevent_main(void)
  17. {
  18. int fd = xopen(*toys.optargs, O_RDWR);
  19. int version;
  20. struct input_event ev;
  21. if (ioctl(fd, EVIOCGVERSION, &version))
  22. perror_exit("EVIOCGVERSION failed for %s", *toys.optargs);
  23. memset(&ev, 0, sizeof(ev));
  24. // TODO: error checking and support for named constants.
  25. ev.type = atoi(toys.optargs[1]);
  26. ev.code = atoi(toys.optargs[2]);
  27. ev.value = atoi(toys.optargs[3]);
  28. xwrite(fd, &ev, sizeof(ev));
  29. }