linux input子系统(一)

root@xxx:/sys/class/input/input0 # cat name                              
sungpiokey
root@xxxx:/sys/class/input/input0 # cd ..
root@xxxx:/sys/class/input # ls
event0
event1
event2
event3
input0
input1
input2
input3

 

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#include <stdlib.h>

struct input_event buff;
int fd;
int read_nu;

int main(int argc, char *argv[])
{
 int i = 0;
 fd = open("/dev/input/event0", O_RDONLY); //may be the powerkey is /dev/input/event1
 if (fd < 0) {
  perror("can not open device usbkeyboard!");
  exit(1);
 }
 
 fprintf(stderr,"richard debug key test\n");

 printf("--fd:%d--\n",fd);
 while(1)
 {
  while(read(fd,&buff,sizeof(struct input_event))==0)
  {
   printf("[richard debug]time %u:%u type:%d code:%d value:%d\n",buff.time.tv_sec,buff.time.tv_usec,buff.type,buff.code,buff.value);
   
  }
  printf("time %u:%u type:%d code:%d value:%d\n",buff.time.tv_sec,buff.time.tv_usec,buff.type,buff.code,buff.value);

  
 }

 close(fd);
 return 1;
}

 

你可能感兴趣的:(linux input子系统(一))