A
@Fat-Zer Dal reply :3You forgot to open the file, so... fd not initialized... just add
fd = open (filename, O_RDONLY); At the beginning of the... the morality of the bass is:
Forget to add control of errors to all systemic challenges (in the case of the
in particular read ()and correct the warning of the compilator. ♪ ♪
And yes, there's a description: type=ev[i].code;This is the corrected code. #include <linux/version.h>
#include <linux/input.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
//---
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x) ((x)%BITS_PER_LONG)
#define BIT(x) (1UL<<OFF(x))
#define LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit))&1)
#define DEV_INPUT_EVENT "/dev/input"
#define EVENT_DEV_NAME "event"
#ifndef EV_SYN
#define EV_SYN 0
#endif
#ifndef SYN_MAX
#define SYN_MAX 3
#define SYN_CNT (SYN_MAX +1)
#endif
#ifndef SYN_MT_REPORT
#define SYN_MT_REPORT 2
#endif
#ifndef SYN_DROPPED
#define SYN_DROPPED 3
#endif
#define NAME_ELEMENT(element) [element] = #element
static const int maxval[EV_MAX + 1] = {
[0 ... EV_MAX] = -1,
[EV_SYN] = SYN_MAX,
[EV_KEY] = KEY_MAX,
[EV_REL] = REL_MAX,
[EV_ABS] = ABS_MAX,
[EV_MSC] = MSC_MAX,
[EV_SW] = SW_MAX,
[EV_LED] = LED_MAX,
[EV_SND] = SND_MAX,
[EV_REP] = REP_MAX,
[EV_FF] = FF_MAX,
[EV_FF_STATUS] = FF_STATUS_MAX,
};
int main() {
printf("losst.ru\n");
printf("Koren: %f\n", sqrt(9));
char *filename;
int fd;
asprintf(&filename, "%s/%s%d", DEV_INPUT_EVENT, EVENT_DEV_NAME,1);
if(!filename)
return EXIT_FAILURE;
if((fd=open(filename, O_RDONLY)) < 0){
perror("evtest");
if(errno == EACCES && getuid() !=0)
fprint(stderr, "You do not have access to %s. Try "
"running as root instead.\n", filename);
return 1;
}
printf("%s\n", filename);
int fdi = 1;
printf("%s%s%d.\n", DEV_INPUT_EVENT, EVENT_DEV_NAME,fdi);
printf("TYT\n");
struct input_event ev[64];
int i; int rd;
fd_set rdfs;
FD_ZERO(&rdfs);
FD_SET(fd, &rdfs);
while(1){
printf("1\n");
printf("1.1\n");
rd = read(fd, ev, sizeof(ev));
printf("2\n");
for (i=0;i<rd/sizeof(struct input_event);i++){
unsigned int type, code;
type=ev[i].type;
code=ev[i].code;
printf("3\n");
printf("Event: time %ld.%06ld, ", ev[i].time.tv_sec, ev[i].time.tv_usec);
if (type == EV_SYN){
if(code == SYN_MT_REPORT)
printf("++++ ++++\n");
else if(code == SYN_DROPPED)
printf(">>>> >>>>\n");
else
printf("----- -----\n");
} else {
printf("type %d , code %d ", type, code);
printf("4\n");
if(type == EV_MSC && (code == MSC_RAW || code == MSC_SCAN))
printf("value %02x\n", ev[i].value);
else
printf("value %d\n", ev[i].value);
}
}
}
return 0;
}
Here's the conclusion: