很久以前的代码拿出来了!熟悉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);
}
}
}