-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.c
80 lines (71 loc) · 2.27 KB
/
input.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// #include <libguile.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
int
get_type (void* data)
{
struct input_event* ev = (struct input_event*)data;
return ev->type;
}
int
get_code (void* data)
{
struct input_event* ev = (struct input_event*)data;
return ev->code;
}
int
get_value (void* data)
{
struct input_event* ev = (struct input_event*)data;
return ev->value;
}
/* int */
/* read_event (int fd) */
/* { */
/* printf("reading from file descriptor:%d\n", fd); */
/* struct input_event ev; */
/* ssize_t n = read (fd, &ev, sizeof (ev)); */
/* printf("aaaabbbbccc\n"); */
/* if (ev.type == EV_KEY && ev.value == 1) */
/* { */
/* printf("hahaha"); */
/* } */
/* return ev.value; */
/* } */
/* int main (void) */
/* { */
/* // The buffer path */
/* const char *dev = "/dev/input/by-path/platform-i8042-serio-0-event-kbd"; */
/* int fd; */
/* fd = open(dev, O_RDONLY); // Open the buffer */
/* if (fd == -1) return EXIT_FAILURE; */
/* struct input_event ev; */
/* ssize_t n; */
/* // Our keylogger need to read every keystroke, so we will need to loop until break */
/* while (1) { */
/* n = read(fd, &ev, sizeof ev); // Read from the buffer */
/* /\* Now, if everything went as expected and a key is */
/* * pressed we should have an event, events looks like this: */
/* * */
/* * struct input_event { */
/* * struct timeval time; */
/* * unsigned short type; // Type of event, we are looking for EV_KEY */
/* * unsigned short code; // Key code in LKC standard (See bellow) */
/* * unsigned int value; // 0 == released; 1 == pressed; 2 == repeated */
/* * }; */
/* *\/ */
/* // Now that we have an event, we have to filter it to just */
/* // fire when the event is EV_KEY and a key is pressed down */
/* if (ev.type == EV_KEY && ev.value == 1)) */
/* printf("Key %d has been pressed\n", ev.code); */
/* // Since we want a safe way to kill the loop safely (closing the stream and all) */
/* if (ev.value == KEY_ESC) break; */
/* // As you see, we can use key defs from input-event-codes.h */
/* } */
/* // And don't forget to close the buffer and exit safely */
/* close(fd); */
/* fflush(stdout); */
/* return EXIT_FAILURE; */
/* } */