blob: 4b5a761aab18e0f38e2fec35832c92af3a9eba1a [file] [log] [blame]
Elliott Hughes8e947fe2014-08-25 22:16:08 -07001#include <errno.h>
2#include <fcntl.h>
3#include <linux/input.h>
4#include <stdint.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08005#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08008#include <sys/ioctl.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08009
10int sendevent_main(int argc, char *argv[])
11{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080012 int fd;
Mark Salyzynaa907762014-05-08 09:31:43 -070013 ssize_t ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080014 int version;
15 struct input_event event;
16
17 if(argc != 5) {
18 fprintf(stderr, "use: %s device type code value\n", argv[0]);
19 return 1;
20 }
21
22 fd = open(argv[1], O_RDWR);
23 if(fd < 0) {
24 fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
25 return 1;
26 }
27 if (ioctl(fd, EVIOCGVERSION, &version)) {
28 fprintf(stderr, "could not get driver version for %s, %s\n", argv[optind], strerror(errno));
29 return 1;
30 }
31 memset(&event, 0, sizeof(event));
32 event.type = atoi(argv[2]);
33 event.code = atoi(argv[3]);
34 event.value = atoi(argv[4]);
35 ret = write(fd, &event, sizeof(event));
Mark Salyzynaa907762014-05-08 09:31:43 -070036 if(ret < (ssize_t) sizeof(event)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080037 fprintf(stderr, "write event failed, %s\n", strerror(errno));
38 return -1;
39 }
40 return 0;
41}