Read the fucking source code below.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <linux/input.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define DIR_PATH "/dev/input"
#define NODE_PREFIX "event"
int main(int argc,char **argv)
{
DIR *tdir;
struct dirent *tdirent;
struct input_event tevent;
unsigned int evbit;
int fd;
unsigned char event_node_name[32];
int node_prefix_len=strlen(NODE_PREFIX);
int ret;
int valid_cnt=0;
int event_type;
//check input parameters.
if(argc<2)
{
printf("usage:%s <0/1>\n",argv[0]);
printf("<0>: scan mouse event nodes\n");
printf("<1>: scan keyboard event nodes\n");
return -1;
}
if(!strncmp(argv[1],"0",1))
{
event_type=EV_REL;
}else if(!strncmp(argv[1],"1",1))
{
event_type=EV_KEY;
}else{
printf("error:invalid scan type!\n");
return -1;
}
tdir=opendir(DIR_PATH);
if(!tdir)
{
printf("open dir failed!\n");
return -1;
}
while((tdirent=readdir(tdir))!=NULL)
{
if(!strncmp(tdirent->d_name,NODE_PREFIX,node_prefix_len))
{
sprintf(event_node_name,"%s/%s",DIR_PATH,tdirent->d_name);
//printf("%s,",event_node_name);
fd=open(event_node_name,O_RDONLY);
if(fd<0)
{
printf("open event node failed:%s\n",strerror(errno));
continue;
}
ret=ioctl(fd,EVIOCGBIT(0,EV_MAX),&evbit);
if(evbit&(0x1<<event_type))
{
printf("%s\n",event_node_name);
valid_cnt++;
}
close(fd);
}
}
closedir(tdir);
return valid_cnt;
}
#!/bin/bash
#brief:to solve match correct event node when EAVCapture starts.
#date:September 17,2015.
#author:zhangshaoyan,shell.albert@gmail.com
#qt's start command line parameters.
mouseplug=
kbdplug=
allplug="-platform linuxfb"
#scan /dev/input directory to get valid event that supports EV_REL.
./evtest.bin 0 > mouse_event.log
mouse_event_cnt=$?
#scan /dev/input diretory to get valid event that supports EV_KEY.
./evtest.bin 1 > kbd_event.log
kbd_event_cnt=$?
#generate the final one-line start parameter.
if [ $mouse_event_cnt -gt 0 ];then
while read line
do
mouseplug="$mouseplug -plugin evdevmouse:$line"
done < mouse_event.log
fi
if [ $kbd_event_cnt -gt 0 ];then
while read line
do
kbdplug="$kbdplug -plugin evdevkeyboard:$line"
done < kbd_event.log
fi
allplug="$allplug $mouseplug $kbdplug"
echo $allplug