📄 key_test.c
字号:
/*********************************************** *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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -