Home | History | Annotate | Download | only in toolbox
      1 #include <errno.h>
      2 #include <fcntl.h>
      3 #include <linux/input.h>
      4 #include <stdint.h>
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 #include <string.h>
      8 #include <sys/ioctl.h>
      9 #include <unistd.h>
     10 
     11 int sendevent_main(int argc, char *argv[])
     12 {
     13     int fd;
     14     ssize_t ret;
     15     int version;
     16     struct input_event event;
     17 
     18     if(argc != 5) {
     19         fprintf(stderr, "use: %s device type code value\n", argv[0]);
     20         return 1;
     21     }
     22 
     23     fd = open(argv[1], O_RDWR);
     24     if(fd < 0) {
     25         fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
     26         return 1;
     27     }
     28     if (ioctl(fd, EVIOCGVERSION, &version)) {
     29         fprintf(stderr, "could not get driver version for %s, %s\n", argv[optind], strerror(errno));
     30         return 1;
     31     }
     32     memset(&event, 0, sizeof(event));
     33     event.type = atoi(argv[2]);
     34     event.code = atoi(argv[3]);
     35     event.value = atoi(argv[4]);
     36     ret = write(fd, &event, sizeof(event));
     37     if(ret < (ssize_t) sizeof(event)) {
     38         fprintf(stderr, "write event failed, %s\n", strerror(errno));
     39         return -1;
     40     }
     41     return 0;
     42 }
     43