]> git.sesse.net Git - keycount/commitdiff
Initial checkin for move to Git (no prior version history available). master
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 22 Jan 2013 16:17:48 +0000 (17:17 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 22 Jan 2013 16:17:48 +0000 (17:17 +0100)
keycount.c [new file with mode: 0644]

diff --git a/keycount.c b/keycount.c
new file mode 100644 (file)
index 0000000..5687203
--- /dev/null
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/input.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/time.h>
+
+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;
+       }
+}