资源简介
getevent源码,可用于测试Linux内核input事件
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#include
#include
#include
#include
#include “getevent.h“
static struct pollfd *ufds;
static char **device_names;
static int nfds;
enum {
PRINT_DEVICE_ERRORS = 1U << 0
PRINT_DEVICE = 1U << 1
PRINT_DEVICE_NAME = 1U << 2
PRINT_DEVICE_INFO = 1U << 3
PRINT_VERSION = 1U << 4
PRINT_POSSIBLE_EVENTS = 1U << 5
PRINT_INPUT_PROPS = 1U << 6
PRINT_HID_DEscriptOR = 1U << 7
PRINT_ALL_INFO = (1U << 8) - 1
PRINT_LABELS = 1U << 16
};
static const char *get_label(const struct label *labels int value)
{
while(labels->name && value != labels->value) {
labels++;
}
return labels->name;
}
static int print_input_props(int fd)
{
uint8_t bits[INPUT_PROP_CNT / 8];
int i j;
int res;
int count;
const char *bit_label;
printf(“ input props:\n“);
res = ioctl(fd EVIOCGPROP(sizeof(bits)) bits);
if(res < 0) {
printf(“ return 1;
}
count = 0;
for(i = 0; i < res; i++) {
for(j = 0; j < 8; j++) {
if (bits[i] & 1 << j) {
bit_label = get_label(input_prop_labels i * 8 + j);
if(bit_label)
printf(“ %s\n“ bit_label);
else
printf(“ %04x\n“ i * 8 + j);
count++;
}
}
}
if (!count)
printf(“ \n“);
return 0;
}
static int print_possible_events(int fd int print_flags)
{
uint8_t *bits = NULL;
ssize_t bits_size = 0;
const char* label;
int i j k;
int res res2;
struct label* bit_labels;
const char *bit_label;
printf(“ events:\n“);
for(i = EV_KEY; i <= EV_MAX; i++) { // skip EV_SYN since we cannot query its available codes
int count = 0;
while(1) {
res = ioctl(fd EVIOCGBIT(i bits_size) bits);
if(res < bits_size)
break;
bits_size = res + 16;
bits = realloc(bits bits_size * 2);
if(bits == NULL) {
fprintf(stderr “failed to allocate buffer of size %d\n“ (int)bits_size);
return 1;
}
}
res2 = 0;
switch(i) {
case EV_KEY:
res2 = ioctl(fd EVIOCGKEY(res) bits + bits_size);
label = “KEY“;
bit_labels = key_labels;
break;
case EV_REL:
label = “REL“;
bit_labels = rel_labels;
break;
case EV_ABS:
label = “ABS“;
bit_labels = abs_labels;
break;
case EV_MSC:
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-08-22 05:37 Getevent-master\
文件 526 2016-08-22 05:37 Getevent-master\Makefile
文件 35 2016-08-22 05:37 Getevent-master\README.md
目录 0 2016-08-22 05:37 Getevent-master\inc\
文件 19028 2016-08-22 05:37 Getevent-master\inc\getevent.h
目录 0 2016-08-22 05:37 Getevent-master\out\
文件 45382 2016-08-22 05:37 Getevent-master\out\getevent
目录 0 2016-08-22 05:37 Getevent-master\src\
文件 21176 2016-08-22 05:37 Getevent-master\src\getevent.c
评论
共有 条评论