Linux下用C代码实现读取按键事件的key code
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
struct timeval begin_time;
int reboot_done = 0;
static void show_event(struct input_event* event)
{
int current_time = event->time.tv_sec * 1000 + (int) event->time.tv_usec/1000;
{
if( event->value == 0 )
{
begin_time.tv_sec = 0;
begin_time.tv_usec = 0;
reboot_done = 0;
printf("%d %d %d [%d.%d]\n", event->type, event->code,
event->value, event->time.tv_sec,(int) event->time.tv_usec/1000 );
printf("press release ! \n");
}
else if( event->value == 1 )