main()
{
struct input_event buf;
{
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
}
fd = open("/dev/input/event1" , O_RDWR);
read(fd, buf, la);
printf("buf,type")
不会写 自己大概写的 帮忙纠正下 用GCC调试
在LINUX下键盘编程 编写键盘应用程序 能够获取键盘按键
答案:2 悬赏:10
解决时间 2021-02-27 22:19
- 提问者网友:℡她的他i☆
- 2021-02-27 09:04
最佳答案
- 二级知识专家网友:情战凌云蔡小葵
- 2021-02-27 10:17
提供一个输入按键应用程序实例,你参考一下。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(void)
{
int buttons_fd;
int key_value,i=0,count;
struct input_event ev_key;
buttons_fd = open("/dev/input/event0", O_RDWR);
if (buttons_fd < 0) {
perror("open device buttons");
exit(1);
}
for (;;) {
count = read(buttons_fd,&ev_key,sizeof(struct input_event));
for(i=0; i<(int)count/sizeof(struct input_event); i++)
if(EV_KEY==ev_key.type)
printf("type:%d,code:%d,value:%d\n", ev_key.type,ev_key.code-1,ev_key.value);
if(EV_SYN==ev_key.type)
printf("syn event\n\n");
}
close(buttons_fd);
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(void)
{
int buttons_fd;
int key_value,i=0,count;
struct input_event ev_key;
buttons_fd = open("/dev/input/event0", O_RDWR);
if (buttons_fd < 0) {
perror("open device buttons");
exit(1);
}
for (;;) {
count = read(buttons_fd,&ev_key,sizeof(struct input_event));
for(i=0; i<(int)count/sizeof(struct input_event); i++)
if(EV_KEY==ev_key.type)
printf("type:%d,code:%d,value:%d\n", ev_key.type,ev_key.code-1,ev_key.value);
if(EV_SYN==ev_key.type)
printf("syn event\n\n");
}
close(buttons_fd);
return 0;
}
全部回答
- 1楼网友:懂得ㄋ、沉默
- 2021-02-27 11:33
linux概述 linux是一个成熟而稳定的网络操作系统。将linux植入嵌入式设备具有众多的优点。首先,linux的源代码是开放的,任何人都可以获取并修改,用之开发自己的产品。其次,lirmx是可以定制的,其系统内核最小只有约134kb。一个带有中文系统和图形用户界面的核心程序也可以做到不足1mb,并且同样稳定。另外,它和多数unix系统兼容,应用程序的开发和移植相当容易。同时,由于具有良好的可移植性,人们已成功使linux运行于数百种硬件平台之上。 然而,linux并非专门为实时性应用而设计,因此如果想在对实时性要求较高的嵌入式系统中运行linux,就必须为之添加实时软件模块。这些模块运行的内核空间正是操作系统实现进程调度、中断处理和程序执行的部分,因此错误的代码可能会破坏操作系统,进而影响整个系统的可靠性和稳定性。linux的众多优点还是使它在嵌入式领域获得了广泛的应用,并出现了数量可观的嵌入式linux系统。 linux的不足 由于在现在的个人电脑操作系统行业中,微软的windows系统仍然占有大部分的份额,绝大多数的软件公司都支持windows。这使得windows上的应用软件应有尽有,而其他的操作系统就要少一些。许多用户在换操作系统的时候都会考虑以前的软件能否继续使用,换了操作系统后是否会不方便。虽然linux具有dos、windows模拟器,可以运行一些windows程序,但windows系统极其复杂,模拟器所模拟的运行环境不可能完全与真实的windows环境一模一样,这就使得一些软件无法正常运行。 许多硬件设备面对linux的驱动程序也不足,不少硬件厂商是在推出windows版本的驱动程序后才编写linux版的。但一些大硬件厂商在这方面做得还不错,他们的linux版驱动程序一般都推出得比较及时。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯