Steward
分享是一種喜悅、更是一種幸福
掌機 - Miyoo Mini - C/C++ - Input Event
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <linux/input.h> // UP: 103 // DOWN: 108 // LEFT: 105 // RIGHT: 106 // A: 57 // B: 29 // X: 42 // Y: 56 // START: 28 // SELECT: 97 // MENU: 1 // L1: 18 // L2: 15 // R1: 20 // R2: 14 // POWER: 116 int main ( int argc, char **argv) { int fd = -1; struct input_event ev = {0}; fd = open ( "/dev/input/event0" , O_RDONLY | O_NONBLOCK | O_CLOEXEC ); if (fd > 0) { while ( read (fd, &ev, sizeof ( struct input_event ))) { if (ev. type == EV_KEY ) { printf ( "code:%d, value:%d\n" , ev. code , ev. value ); } } close (fd); } return 0; } |