#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "stdio.h"
#define KEY0VALUE 0xF0
int main(int argc,char * argv[])
{
int i_fd;
char ach_buf[2] ={0,0};
unsigned char keyValue[2]={0};
ach_buf[0] = atoi(argv[1]);
i_fd = open("/dev/key_node",O_RDWR);
if(i_fd < 0)
{
printf("open error\n");
}
else
{
printf("open success"); //此处去除\n后,按键之后才会打印
}
//write(i_fd,ach_buf,sizeof(ach_buf));
while (1)
{
read(i_fd,keyValue,sizeof(keyValue));
//printf(" %d",keyValue[0]);
if((int)keyValue[0] == KEY0VALUE)
{
printf("---------------------------------- %d\n",keyValue[0]);
keyValue[0] = 0;
}
}
//printf("buf is %s \n",ach_buf2);
close(i_fd);
return 0;
}
打印时 printf(“---------------------------------- %d\n”,keyValue[0]);处不加\n则无论按多少次按键都无法打印