Linux 键盘模拟测试

来源:互联网 发布:热血沙尘 全套源码 编辑:程序博客网 时间:2024/06/05 08:21
#include <stdio.h>#include <linux/input.h>#include <fcntl.h>#include <sys/time.h>#include <unistd.h>int main ()  {    int keys_fd;    char ret[2];    struct input_event t;    keys_fd = open ("/dev/input/event2", O_RDONLY);    if (keys_fd <= 0)      {        printf ("open /dev/input/event2 device error!\n");        return 0;      }    while (1)      {        if (read (keys_fd, &t, sizeof (t)) == sizeof (t))          {            if (t.type == EV_KEY)              if (t.value == 0 || t.value == 1)          {                printf ("key %d %s\n", t.code,                        (t.value) ? "Pressed" : "Released");            if(t.code==KEY_ESC)                break;          }          }      }    close (keys_fd);    return 0;  }  
0 0
原创粉丝点击