--- /dev/null
+#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;
+ }
+}