Elliott Hughes | 8e947fe | 2014-08-25 22:16:08 -0700 | [diff] [blame] | 1 | #include <errno.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <linux/input.h> |
| 4 | #include <stdint.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 8 | #include <sys/ioctl.h> |
Elliott Hughes | 0badbd6 | 2014-12-29 12:24:25 -0800 | [diff] [blame] | 9 | #include <unistd.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 10 | |
| 11 | int sendevent_main(int argc, char *argv[]) |
| 12 | { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 13 | int fd; |
Mark Salyzyn | aa90776 | 2014-05-08 09:31:43 -0700 | [diff] [blame] | 14 | ssize_t ret; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 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)); |
Mark Salyzyn | aa90776 | 2014-05-08 09:31:43 -0700 | [diff] [blame] | 37 | if(ret < (ssize_t) sizeof(event)) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 38 | fprintf(stderr, "write event failed, %s\n", strerror(errno)); |
| 39 | return -1; |
| 40 | } |
| 41 | return 0; |
| 42 | } |