Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Linux Kernel Keystroke Counter
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
robbyjo
Guru
Guru


Joined: 06 Apr 2003
Posts: 462

PostPosted: Wed Jun 22, 2005 10:25 pm    Post subject: Reply with quote

Perhaps we can set the duplication to 3 or 4. But I can hardly think of words that has 3 identical letters in a row, except perhaps Kashyyyk. Hmm...
Back to top
View user's profile Send private message
alinv
Guru
Guru


Joined: 19 Nov 2002
Posts: 395
Location: Bucharest

PostPosted: Wed Jun 22, 2005 10:31 pm    Post subject: Reply with quote

robbyjo wrote:
Perhaps we can set the duplication to 3 or 4. But I can hardly think of words that has 3 identical letters in a row, except perhaps Kashyyyk. Hmm...

What about numbers like 1000000 or hex AAAABBBB1111...?
_________________
Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.
S.B.
Back to top
View user's profile Send private message
mirko_3
l33t
l33t


Joined: 02 Nov 2003
Posts: 605
Location: Birreria

PostPosted: Thu Jun 23, 2005 2:23 pm    Post subject: Reply with quote

I mean... do you really need it to be that precise?
_________________
Non fa male! Non fa male!
Back to top
View user's profile Send private message
Redeeman
l33t
l33t


Joined: 25 Sep 2003
Posts: 958
Location: Portugal

PostPosted: Thu Jun 23, 2005 2:37 pm    Post subject: Reply with quote

isnt it possible to catch a keypress event so that you just increment each time a key is pressed, and ignore the repeat thing?
Back to top
View user's profile Send private message
dsf
n00b
n00b


Joined: 16 Nov 2004
Posts: 21

PostPosted: Fri Jun 24, 2005 1:10 am    Post subject: Reply with quote

People are indeed correct about the bug with repeats -- good eye and catch. :)

Right now, the code assumes that if it has seen the same character before, that it is a repeat. This was required because of the way the code is written to ignore the actual keypress repeat events.

It could probably be restructured differently in some way, along with an additional check or two, and perhaps adding an additional variable or two to track this stuff.

So I will leave this as an exercise in code modification for anyone that may be interested in fixing it. Shouldn't be too hard.
Back to top
View user's profile Send private message
rihteri
n00b
n00b


Joined: 01 Jun 2003
Posts: 36
Location: Seinäjoki, Finland

PostPosted: Thu Oct 13, 2005 12:31 pm    Post subject: Reply with quote

Nice hacks, but if you really only want to count the keystrokes, try this little python script I wrote inspired by dsf:s comment about doing this in userspace. Seems the problem is really simple.

Code:

i=0

event=file('/dev/input/event0','r')

while (1):
        event.read(96)
        i=i+1
        print i


Of course this only starts counting when it is started. Output could be better as well. But I think it counts right. You might have to alter the read size if you have non-i386-32bit processor, I think. And change the device if needed.

EDIT:

Seems like the event interface also outputs the time an event occurs.

Code:

struct input_event {
        struct timeval time;
        __u16 type;
        __u16 code;
        __s32 value;
};


Who wants to write a script to draw a graph of keystrokes relative to time? =)
_________________
I do speak more freely if I get free beer...
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Thu Oct 13, 2005 5:38 pm    Post subject: Reply with quote

where are these /dev/input/event* files documented? how did you know event0 was the keyboard?
_________________
http://www.desertsol.com/~kevin/ppc
Back to top
View user's profile Send private message
rihteri
n00b
n00b


Joined: 01 Jun 2003
Posts: 36
Location: Seinäjoki, Finland

PostPosted: Thu Oct 13, 2005 5:59 pm    Post subject: Reply with quote

zojas wrote:
where are these /dev/input/event* files documented? how did you know event0 was the keyboard?


http://www.frogmouth.net/hid-doco/p13.html has something. http://www.charmed.com/txt/input-programming.txt has some more.

About making the script... I tried 'cat /dev/input/event0' etc, noticed event0 is my keyboard, event1 is mouse etc. I was actually trying to get my synaptics touchpad working, thats why I came across this thred as well.

When you open up /usr/src/linux/include/input.h you can start guessing the format of an input event - seems I got the size right eventually, at least on my system. I'm really pretty clueless about this thing, I'm not even sure about anything I said before :P

EDIT:

My script counts repeats wrong. It really needs some tuning.
_________________
I do speak more freely if I get free beer...
Back to top
View user's profile Send private message
mephist0
Tux's lil' helper
Tux's lil' helper


Joined: 19 Sep 2005
Posts: 94
Location: Germany, Frankfurt/Main

PostPosted: Sat Oct 15, 2005 7:07 pm    Post subject: Re: Linux Kernel Keystroke Counter Reply with quote

zojas wrote:
I hacked the keyboard driver in the kernel so it counts every keystroke and reports it through /proc/keystrokes.

You can go to http://www.desertsol.com/~kevin/keystroke_patch
to get a patch for 2.4.18 or 2.4.19-gentoo-r7.

Just patch, recompile, install, reboot, then

Code:
cat /proc/keystrokes


really cool, thanks alot !!
_________________
There is only one God, and his name is Death. And there is only one thing we say to Death: 'Not today!'

Photography portfolio
Back to top
View user's profile Send private message
rihteri
n00b
n00b


Joined: 01 Jun 2003
Posts: 36
Location: Seinäjoki, Finland

PostPosted: Fri Oct 21, 2005 8:49 pm    Post subject: Reply with quote

I got interested in this thing, so heres a little improved version of the userspace keypress counter. Compile with 'g++ -o key key.cc'. Mostly ripped of from http://www.frogmouth.net/hid-doco/c193.html. Should work fine, ignores repeats and makes no (?) errors =)

key.cc:
Code:
#include <fstream>
#include <linux/input.h>
#include <iostream>

using namespace std;

int main() {

  struct input_event ev;
  int i = 0;
 
  //Open /dev/input/event0
  ifstream fd ("/dev/input/event0", ios::binary);
  if(! fd.good()) {
    cout << "failed to open /dev/input/event0, you are propably not root" << endl;
    exit(1);
  }

  while (1) {
    fd.read( reinterpret_cast<char *> (&ev), sizeof(struct input_event) );
    if (ev.value == 1) {
      i++;
      cout << i << " keys pressed." << endl;
    }
  }
}

_________________
I do speak more freely if I get free beer...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum