From 03ecc8e4289c7e214671e11cca72885758b85c6a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 22 Jan 2013 17:17:48 +0100 Subject: [PATCH 1/1] Initial checkin for move to Git (no prior version history available). --- keycount.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 keycount.c diff --git a/keycount.c b/keycount.c new file mode 100644 index 0000000..5687203 --- /dev/null +++ b/keycount.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + FILE *log = fopen("/var/log/keycount.log", "a"); + struct input_event iev; + time_t start = time(NULL); + unsigned count = 0; + int fd = open("/dev/input/event0", O_RDONLY); + if (fd == -1) { + perror("/dev/input/event0"); + exit(1); + } + + for ( ;; ) { + int ret = read(fd, &iev, sizeof(iev)); + time_t now; + if (ret != sizeof(iev)) { + perror("read"); + exit(1); + } + + if (iev.type != EV_KEY) + continue; + if (iev.value != 1) + continue; + + // see if we want to write out + now = time(NULL); + if (now/60 != start/60) { + fprintf(log, "%u %u\n", (start/60)*60, count); + fflush(log); + count = 0; + start = now; + } + ++count; + } +} -- 2.39.2