--- lkl/output.c        2005-10-17 19:15:20.000000000 +0000
+++ output.c    2008-05-10 16:06:15.000000000 +0000
@@ -32,16 +32,100 @@
 
 #include "lkl.h"
 
+/*  
+ *  This lkl-0.1.1 patch will make lkl (Linux Key Logger) log only (at stop time) the totality of keyboard hits during the run.
+ *  example log entry:
+ *  Sat May 10 17:25:22 2008 - Sat May 10 17:25:29 2008 : 24
+ *
+
+       suggested usage to create a keystroke count and plot it using gnuplot :
+      
+#wget http://puzzle.dl.sourceforge.net/sourceforge/lkl/lkl-0.1.1.tar.gz
+#tar xzf lkl-0.1.1.tar.gz
+#patch lkl/output.c lkl-0.1.1-counter.patch
+#cd lkl && ./configure && make && cd ..
+#lkl/lkl -k lkl/it_km -o /var/log/keystrokes.log
+
+# cut and paste this in your shell and the \$ will become $
+
+cat > ks.sh << pizza
+#!/bin/sh
+cat /var/log/keystrokes.log | \
+perl -e 'use Date::Parse ; while(<STDIN>){ chomp;(\$t,\$c)= split(/ : /);'\
+'(\$t1,\$t2)=split(/ - /,\$t);\$t1=str2time(\$t1);\$t2=str2time(\$t2);'\
+'printf  ("%10d %10d\n%10d %10d\n", \$t1, (\$c+1)/(\$t2-\$t1), \$t2, 0 ) ;  }'  > keystrokes.dat && \
+       echo -e "set xdata time\n" "set timefmt '%s'\n" "set format x '%D@%H:%M:%S'\n" \
+       "plot 'keystrokes.dat' using 1:2 with boxes\npause 10000" | gnuplot
+pizza
+ *
+ * */
+#define ONLY_LOG_COUNT 1
+#ifdef ONLY_LOG_COUNT
+#include <signal.h>
+#endif
 char *asciitab[TABLE_SIZE], *asciitab_shift[TABLE_SIZE], *asciitab_alt[TABLE_SIZE];
 
+#ifdef ONLY_LOG_COUNT
+struct lkl * g_lkl;
+int g_count=0;
+time_t start_timet;    /* first keystroke timet */
+
+static void log_count_and_exit(int signal)
+{
+       struct lkl *lkl=g_lkl;
+       FILE *fp;
+
+       static char strtemp[128];
+       time_t timet;
+
+       bzero(strtemp, 128);
+       time(&timet);
+       strcat(strtemp, ctime(&start_timet));
+       if(strlen(strtemp)>2) strtemp[strlen(strtemp)-1]='\0';
+       strcat(strtemp," - ");
+       strcat(strtemp, ctime(&timet));
+       if(strlen(strtemp)>2) strtemp[strlen(strtemp)-1]='\0';
+
+       if(lkl->outfile == NULL){
+               printf("(%d)", g_count);
+       }else{
+               if((fp = fopen(lkl->outfile, "a")) == NULL){
+                       perror("fopen()");
+                       exit(-1);
+               }
+  
+               fprintf(fp, "%s : %d\n", strtemp, g_count);
+               fclose(fp);
+       }
+       exit(0);
+}
+#endif
+
+
 void do_output(char c, struct lkl *lkl)
 {
        FILE *fp;
        char *ascii;
+#ifdef ONLY_LOG_COUNT
+       static long int count = 0;
+       struct sigaction act,old;
+
+       if(!count){
+       time(&start_timet);
+       g_lkl=lkl;
+       memset(&act,0,sizeof(act));
+       act.sa_handler = log_count_and_exit;
+       sigemptyset(&act.sa_mask);
+       sigaction(SIGQUIT,&act,&old);
+       }
+       ++count;
+       g_count=count;
+#endif
 
        ascii = code2ascii(c, lkl);
        if(ascii == NULL) ascii = "NULL";
 
+#ifndef ONLY_LOG_COUNT
        if(lkl->outfile == NULL){
                printf("(%s)", ascii);
        }else{
@@ -53,6 +137,7 @@
                fprintf(fp, "%s", ascii);
                fclose(fp);
        }
+#endif
 
        if(lkl->syslog) syslog(LOG_INFO, "%s", ascii);