key_test.c
来自「嵌入式linux 开发板驱动程序」· C语言 代码 · 共 54 行
C
54 行
/*********************************************** *single key driver test function* *date : created at 2007-09-19 by baijb**********************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <errno.h>#include <fcntl.h>#include <sys/types.h>#define PATH "/dev/key/0" //device fileint main(void){ int fd; int result; int key_value; int times = 0; fd = open(PATH, 0); if (fd < 0) { printf("Failed to open key_driver\n"); exit(1); } do { result = read(fd, &key_value, sizeof(key_value)) == sizeof(key_value); if (!result) { if (errno == EINVAL) printf("Wrong size!\n"); goto failed; } if(key_value == 1) { printf("key-19 or key-20 pressed!\n"); printf("pressed %d times\n", ++times); } else if(key_value == 2) { printf("key-17 or key-18 pressed!\n"); printf("pressed %d times\n", ++times); } }while(times < 10); failed: close(fd); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?