首页 > 其他 > 详细

获取键盘按键值

时间:2015-03-04 16:53:35      阅读:253      评论:0      收藏:0      [点我收藏+]

很久以前的代码拿出来了!熟悉linux键盘驱动的这段代码太容易啦!


/*获取键盘的按值*/
#include <stdio.h>
#include <linux/input.h>
#include <stdlib.h>
#include <fcntl.h>
#include <assert.h>
struct info
{
	struct timeval time;
	unsigned short type;
	unsigned short code;
	unsigned int value;
};
int main()
{
	int fd;
	struct info node;
	fd = open("/dev/input/event0",O_RDWR);
	if(fd<0)
	{
		printf("open error!\n");
	}
	//assert(fp);
	while(1)
	{
		long i=0;
		fflush(stdout);
		read(fd,&node,sizeof(struct info));
		if(node.type == EV_KEY)
		{
			printf("code :%d\n",node.code);
			printf("value: %d\n",node.value);
		}
	}
	
}


获取键盘按键值

原文:http://blog.csdn.net/zhangxxxww/article/details/44062155

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!