views:

66

answers:

1

Is it possible to record a user's input into an HTML textfield, and playback at a later date in realtime? One way I can think of would be to capture each keyDown event and the time delta (accurate to a few hundred ms), and store the pairs together.

Can you think of a better/more efficient way?

+2  A: 

The handler which is returned by KeyDown handler contains all the informations you need to do what you want.

Try this in firebug:

$('#your-input').keydown(
    function(e) { 
        console.log(e.timeStamp);
        console.log(e.keyCode);
    }
);

You just have to store the data from the handler (var e) which has timeStamp property and keyCode.

You can then set a timer with the difference between to keydown to simulate them.

Boris Guéry