#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define DEV_PATH0 "/dev/input/event0" //button1 button2对应的是event0
#define DEV_PATH3 "/dev/input/event3" //button3 button4对应的是event3
int main(int argc, char **argv)
{
int i = 0;
int but1 = 0;
int but2 = 0;
int but3 = 0;
int but4 = 0;
int times = 5; //缺省超时时间
int ret = 0;
char buffer[128] = {0};
int keys_fd = 0;
struct input_event t;
if (argc == 2) {
times = (int)strtoul(argv[1], NULL, 10); //传入的超时时间
}
keys_fd=open(DEV_PATH0, O_RDONLY | O_NDELAY); //非阻塞的方式打开
if(keys_fd <= 0)
{
printf("open /dev/input/event0 device error!\n");
return -1;
}
for(i=0;i<tim
button按键测试
最新推荐文章于 2024-07-02 10:01:12 发布
该博客介绍了一个在Linux系统中用于测试硬件上四个按键的C语言程序。程序通过读取/dev/input/event0(对应按键1和2)和/dev/input/event3(对应按键3和4)的输入事件来检测按键是否被按下。程序使用非阻塞方式打开设备文件,并在设定的超时时间内检查按键状态。如果所有按键都被按下,则测试成功,否则测试失败。
摘要由CSDN通过智能技术生成