New binary and device selection list and device parameter.

This commit is contained in:
retoor 2024-12-26 00:33:01 +01:00
parent fc3586eac9
commit d17bd484ff
2 changed files with 22 additions and 9 deletions

BIN
tikker

Binary file not shown.

View File

@ -7,6 +7,8 @@
#include <sys/ioctl.h>
#include <unistd.h>
#define DATABASE_NAME "tikker.db"
#define DEVICE_TO_READ_DEFAULT "keyboard"
#define MAX_DEVICES 32
#define DEVICE_PATH "/dev/input/event"
@ -50,19 +52,21 @@ const char *keycode_to_char[] = {
int is_keyboard(int fd) {
char device_name[256] = {0};
char * resolve_device_name(int fd) {
static char device_name[256];
device_name[0] = 0;
if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) < 0) {
return 0;
}
return strstr(device_name, "keyboard") != NULL;
return device_name;
}
int main() {
int main(int argc, char *argv[]) {
int db = sormc("tikker.db");
char * device_to_read = rargs_get_option_string(argc, argv, "--device", DEVICE_TO_READ_DEFAULT);
int db = sormc(DATABASE_NAME);
ulonglong times_repeated = 0;
ulonglong times_pressed = 0;
@ -81,17 +85,26 @@ int main() {
if (fd < 0) {
continue;
}
char * device_name = resolve_device_name(fd);
if(!device_name)
{
close(fd);
continue;
}
bool is_device_to_read = strstr(device_name, device_to_read) != NULL;
printf("[%s] %s. Mount: %s.\n", is_device_to_read ? "-" : "+", device_name, device_path);
if (is_keyboard(fd)) {
if (is_device_to_read) {
keyboard_fds[num_keyboards++] = fd;
printf("Found keyboard: %s\n", device_path);
} else {
close(fd);
}
}
if (num_keyboards == 0) {
fprintf(stderr, "No keyboard found.\n");
fprintf(stderr, "No keyboard found. Do you execute under root?\n"
"If your device is listed above with a minus[-] in front of it,\n"
"execute this application using --device='[DEVICE_NAME]'\n");
return 1;
}