New binary and device selection list and device parameter.
This commit is contained in:
parent
fc3586eac9
commit
d17bd484ff
31
tikker.c
31
tikker.c
@ -7,6 +7,8 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define DATABASE_NAME "tikker.db"
|
||||||
|
#define DEVICE_TO_READ_DEFAULT "keyboard"
|
||||||
#define MAX_DEVICES 32
|
#define MAX_DEVICES 32
|
||||||
#define DEVICE_PATH "/dev/input/event"
|
#define DEVICE_PATH "/dev/input/event"
|
||||||
|
|
||||||
@ -50,19 +52,21 @@ const char *keycode_to_char[] = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int is_keyboard(int fd) {
|
char * resolve_device_name(int fd) {
|
||||||
char device_name[256] = {0};
|
static char device_name[256];
|
||||||
|
device_name[0] = 0;
|
||||||
|
|
||||||
if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) < 0) {
|
if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return device_name;
|
||||||
return strstr(device_name, "keyboard") != NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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_repeated = 0;
|
||||||
ulonglong times_pressed = 0;
|
ulonglong times_pressed = 0;
|
||||||
@ -81,17 +85,26 @@ int main() {
|
|||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
continue;
|
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;
|
keyboard_fds[num_keyboards++] = fd;
|
||||||
printf("Found keyboard: %s\n", device_path);
|
|
||||||
} else {
|
} else {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_keyboards == 0) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user