zym0805

键盘 Input子系统

应用层测试代码

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <linux/input.h>

#include <sys/fcntl.h>

int main(int argc, char *argv[])

{

       int fd = -1;

       int num;

       size_t rb;

       int version;

       char name[20];

       struct input_event ev;

       int i=0;

       if ((fd = open("/dev/input/event1", O_RDONLY)) < 0)  //打开设备

       {

              perror("open error");

              exit(1);

       }

       while(1)

       {

              rb = read(fd, &ev, sizeof(struct input_event));  //读取设备

              if (rb < (int)sizeof(struct input_event))  //读取错误

              {

                     perror("read error");

                     exit(1);

              }

              if (EV_KEY==ev.type)                     //读取的是否是按键内容

              {

                     if (1 == ev.value)                   //key1被按下

                     printf("key is pressed\n");

                     else                                                       //key1被释放

                     printf("key is released\n");

              }     

       }    

        close(fd);

       return 0;

}

分类:

技术点:

相关文章:

  • 2021-11-22
  • 2021-08-25
  • 2021-11-01
  • 2022-12-23
  • 2021-11-27
  • 2021-12-03
  • 2021-10-19
猜你喜欢
  • 2021-05-24
  • 2021-12-05
  • 2021-12-10
  • 2021-11-19
  • 2021-12-06
  • 2021-06-13
相关资源
相似解决方案