rsriram has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I want to develop a script, which once exectued, will start writing/appending all the keystrokes made by the user to a text file. I tried searching CPAN, but could not identify a module which will suit my need. Could anyone suggest a module or a logic for this?

Replies are listed 'Best First'.
Re: Appending keystrokes to a text file
by ikegami (Patriarch) on Dec 16, 2008 at 07:39 UTC

    Files can only contain bytes, not keystrokes. So, in addition to finding a method of obtaining the keystrokes (Term::ReadKey?), you need to decide how you want to store them.

    Update: I interpreted your question rather literally, but you didn't give us much to go on.

      some work around using Term::Readkey

      It may help for your requirement

      #! /usr/bin/perl use Term::ReadKey; ReadMode 4; # Turn off controls keys open(FH,'>',"file"); $|=1; ## To read 10 characters and write into the file $i=0; ## for reading 10 characters.... while ( $i<10) { until (defined ($key = ReadKey(-1))) {} print FH "$key\n"; $i++; } close FH; ReadMode 0; # Reset tty mode before exiting

        Thank you very much! But what I am looking for is, when this script is running, any keys strokes made in other applications too, for example, I have started this script and type something in notepad, those keys should also be recorded into this file.

Re: Appending keystrokes to a text file
by zentara (Cardinal) on Dec 16, 2008 at 15:11 UTC
    Dosn't the unix utility "script" do this?

    The problem is what do you mean by user? A user typing at a single terninal? All keystrokes any user enters? If that is the case, you will be better off with a kernel patch.....google for "linux kernel patch keystroke recorder".


    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Appending keystrokes to a text file
by Lawliet (Curate) on Dec 16, 2008 at 19:36 UTC

    .oO(Keylogger?)

    I'm so adjective, I verb nouns!

    chomp; # nom nom nom