zoukankan      html  css  js  c++  java
  • 键盘 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 ");

                         else                                                       //key1被释放

                         printf("key is released ");

                  }     

           }    

            close(fd);

           return 0;

    }

  • 相关阅读:
    BNUOJ 12756 Social Holidaying(二分匹配)
    HDU 1114 Piggy-Bank(完全背包)
    HDU 2844 Coins (多重背包)
    HDU 2602 Bone Collector(01背包)
    HDU 1171 Big Event in HDU(01背包)
    HDU 2571 命运 (入门dp)
    HDU 1069 Monkey and Banana(最长递减子序列)
    HDU 1160 FatMouse's Speed (最长上升子序列)
    HDU 2594 KMP
    POJ 3783 Balls --扔鸡蛋问题 经典DP
  • 原文地址:https://www.cnblogs.com/zym0805/p/5983885.html
Copyright © 2011-2022 走看看