日期:2014-05-16 浏览次数:20765 次
#include <stdio.h> #include <stdlib.h> #include <linux/input.h> #include <asm/fcntl.h> int main(void) { int ret; int fp = 0; struct input_event key_event; fp=open("/dev/input/event0", O_RDONLY); if(fp<0){ printf("Error: cannot open ir keypad device.\n"); return -1; } while(1){ ret = read(fp, &key_event, sizeof(struct input_event)); if(ret != sizeof(struct input_event)) { printf("read is error. \n"); return -1; } switch(key_event.value) { case 0: printf("release %d.\n", key_event.code); break; case 1: printf("press %d.\n", key_event.code); break; default: printf("value is error.\n"); break; } } close(fp); return 0; }