btn_test.c
来自「这份源码是用基于QT2410的嵌入式Linux开发的按键驱动程序以及测试程序.」· C语言 代码 · 共 50 行
C
50 行
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/select.h>#include <sys/time.h>int main(void){ int buttons_fd; int key_value,key_bk; key_value=0; key_bk=0; buttons_fd = open("/dev/qt2410_btns", 0); if (buttons_fd < 0) { perror("open device buttons"); exit(1); } for (;;) { if (read(buttons_fd, &key_value, sizeof key_value)!= sizeof key_value) { perror("read buttons\n"); printf("Error in read button /n"); continue; } else { key_value &= 0x000f; if(key_value != key_bk) { printf("buttons_value: %d\n", key_value); key_bk = key_value; } } } close(buttons_fd); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?