键盘 Input子系统
應(yīng)用層測試代碼
#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)? //打開設(shè)備
?????? {
????????????? perror("open error");
????????????? exit(1);
?????? }
?????? while(1)
?????? {
????????????? rb = read(fd, &ev, sizeof(struct input_event));? //讀取設(shè)備
????????????? if (rb < (int)sizeof(struct input_event))? //讀取錯誤
????????????? {
???????????????????? perror("read error");
???????????????????? exit(1);
????????????? }
????????????? if (EV_KEY==ev.type)???????????????????? //讀取的是否是按鍵內(nèi)容
????????????? {
???????????????????? if (1 == ev.value)?????????????????? //key1被按下
???????????????????? printf("key is pressed\n");
???????????????????? else?????? ????????????????????????????????????????????? ??//key1被釋放
???????????????????? printf("key is released\n");
????????????? }?????
?????? }????
?????? ?close(fd);
?????? return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/zym0805/p/5983885.html
總結(jié)
以上是生活随笔為你收集整理的键盘 Input子系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UAF学习之Adobe reader C
- 下一篇: Spring-profile设置