I need to record my own keystroke data for some academic research. I wrote a regular keylogger for Windows, but now I need to write one for a Unix environment, with the constraint that I have only user-level access. Furthermore, I'm only in the terminal, so this problem is more narrow in one sense.

What would be the best way to do this? Is there some easy way to sort of fork my input so that it goes to a special program as well as to Bash?

I'm using Python or Ruby if there's a lot of code involved, or Bash would work.

The system is Red Hat Enterprise Linux 6.3 if it matters.

Update: I should have listed out more detailed requirements:

  • Need to record timing somehow (script -t seems to be fine)
  • Need to handle special keystrokes (it matters if a Ctrl or a shift was hit in-between keystrokes); so far as possible, every key event should be handled
  • Optional: Might also be good to differentiate key down and key up events for more fine-grained data.

If you're only using the terminal, there's an easy solution: script does what you want and more: it logs both input and output.

| improve this answer | |
  • This looks very handy, especially with the -t option. Is there any way to handle all the special keystrokes as well, such as shift and ctrl? I will update the question. – jtpereyda Dec 6 '12 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.