2014-08-26 13:16:08 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <stdint.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
2014-12-30 04:24:25 +08:00
|
|
|
#include <unistd.h>
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
int sendevent_main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd;
|
2014-05-09 00:31:43 +08:00
|
|
|
ssize_t ret;
|
2009-03-04 11:32:55 +08:00
|
|
|
int version;
|
|
|
|
struct input_event event;
|
|
|
|
|
|
|
|
if(argc != 5) {
|
|
|
|
fprintf(stderr, "use: %s device type code value\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(argv[1], O_RDWR);
|
|
|
|
if(fd < 0) {
|
|
|
|
fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (ioctl(fd, EVIOCGVERSION, &version)) {
|
|
|
|
fprintf(stderr, "could not get driver version for %s, %s\n", argv[optind], strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
memset(&event, 0, sizeof(event));
|
|
|
|
event.type = atoi(argv[2]);
|
|
|
|
event.code = atoi(argv[3]);
|
|
|
|
event.value = atoi(argv[4]);
|
|
|
|
ret = write(fd, &event, sizeof(event));
|
2014-05-09 00:31:43 +08:00
|
|
|
if(ret < (ssize_t) sizeof(event)) {
|
2009-03-04 11:32:55 +08:00
|
|
|
fprintf(stderr, "write event failed, %s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|