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