zoukankan      html  css  js  c++  java
  • Linux C中读取/dev/input/event设备来判断键盘按键是否按下

    ////

    include <stdio.h>

    include <linux/input.h>

    include <stdlib.h>

    include <sys/types.h>

    include <sys/stat.h>

    include <fcntl.h>

    define DEV_PATH "/dev/input/event2" //difference is possible

    int main()
    {
    int keys_fd;
    char ret[2];
    struct input_event t;
    keys_fd=open(DEV_PATH, O_RDONLY);
    if(keys_fd <= 0)
    {
    printf("open /dev/input/event2 device error! ");
    return -1;
    }
    while(1)
    {
    if(read(keys_fd, &t, sizeof(t)) == sizeof(t))
    {
    if(t.typeEV_KEY)
    if(t.value
    0 || t.value==1)
    {
    printf("key %d %s ", t.code, (t.value) ? "Pressed" : "Released");
    if(t.code == KEY_ESC)
    break;
    }
    }
    }
    close(keys_fd);
    return 0;
    }

  • 相关阅读:
    查看web访问日志各url shell
    分页公式
    编译hadoop2.6.0源码
    淘宝微信支付
    nodejs hot deployment
    nwjs
    css小技巧
    webpack babel 相关文章
    nodejs web framework
    swiper
  • 原文地址:https://www.cnblogs.com/hllak/p/4933823.html
Copyright © 2011-2022 走看看