19 #include <linux/input.h>
26 int main(
int argc,
char *argv[])
30 printf(
"test_uinput: <device file path>\r\n");
34 const char *devFile = argv[1];
36 int fd = open(devFile, O_RDONLY|O_SYNC);
38 struct input_event ev;
39 const int count =
sizeof(ev);
42 int ret = read(fd, &ev, count);
44 printf(
"Getting input [%ld.%ld] - %d %d %d\r\n",
45 ev.time.tv_sec, ev.time.tv_usec,
49 if (ev.type == EV_KEY) {
50 if (ev.value >= 0 && ev.value <=2) {
51 printf(
"[%ld].[%ld] : Key [%d] [%s]\r\n",
52 ev.time.tv_sec, ev.time.tv_usec,
54 (ev.value == 1) ?
"+++++PRESSED" : ((ev.value == 0) ?
"=====Release" :
"......."));
57 else if (ev.type == EV_SYN) {
58 printf(
"[%ld].[%ld] : SYN [%s]\r\n",
59 ev.time.tv_sec, ev.time.tv_usec,
60 (ev.value == SYN_REPORT) ?
"SYN_REPORT" :
"SYN_OTHER");
64 printf(
"read() input event returned %d failure [%s]\r\n", ret, strerror(errno));
70 printf(
"open file %s failed [%s]\r\n", devFile, strerror(errno));