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> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 9 | |
| 10 | int sendevent_main(int argc, char *argv[]) |
| 11 | { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 12 | int fd; |
Mark Salyzyn | aa90776 | 2014-05-08 09:31:43 -0700 | [diff] [blame] | 13 | ssize_t ret; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 14 | 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 Salyzyn | aa90776 | 2014-05-08 09:31:43 -0700 | [diff] [blame] | 36 | if(ret < (ssize_t) sizeof(event)) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 37 | fprintf(stderr, "write event failed, %s\n", strerror(errno)); |
| 38 | return -1; |
| 39 | } |
| 40 | return 0; |
| 41 | } |