blob: 4d0ca1760db9f8845e32368d5632e1691ba21561 [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>
Elliott Hughes0badbd62014-12-29 12:24:25 -08009#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080010
11int sendevent_main(int argc, char *argv[])
12{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080013 int fd;
Mark Salyzynaa907762014-05-08 09:31:43 -070014 ssize_t ret;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080015 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));
Mark Salyzynaa907762014-05-08 09:31:43 -070037 if(ret < (ssize_t) sizeof(event)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080038 fprintf(stderr, "write event failed, %s\n", strerror(errno));
39 return -1;
40 }
41 return 0;
42}