I'd like to make a dynamic module where a user types in text and Mathematica records the typed text and time at which each key is pressed. The time could be relative to the start or relative to the time of the previous keypress.

For instance, typing "Hello" could lead to the output


where the times are relative to the previous keypress and measured in milliseconds.

I found this blog post that specifically measures the time spent typing "wolfram". That DynamicModule does way more than what I need, including having a very nice interface. I'm having a hard time figuring out what I can remove and how to extend the functionality beyond the letters of "wolfram" to arbitrary-length text.

Any help is appreciated.


1 Answer 1


Here is a minimal implementation using EventHandler.

DynamicModule[{keys = {}, starttime = Now},
     InputField["", String], {"KeyDown" :> 
      (AppendTo[keys, {CurrentValue["EventKey"], Now - starttime}])}, 
     PassEventsDown -> True]}, {Dynamic[Grid@keys]}}, 
  Alignment -> Left]]

enter image description here

  • $\begingroup$ This works well. I modified it so that keys is a global variable that I can access outside of the dynamic module to analyze; this got me so much farther along than I would have on my own. Thanks. $\endgroup$
    – GregH
    Commented Feb 22 at 19:31
  • $\begingroup$ @GregH how did you get keys out as a global variable? $\endgroup$
    – Charlie
    Commented May 15 at 21:05
  • $\begingroup$ @Charlie, just omit the DynamicModule, which otherwise serves to localize the symbols. $\endgroup$
    – Domen
    Commented May 15 at 22:02
  • 1
    $\begingroup$ @Charlie I put the keys={} line outside the DynamicModule, as in keys={}; DynamicModule[.... $\endgroup$
    – GregH
    Commented May 16 at 13:02
  • $\begingroup$ wow that's cool thanks. $\endgroup$
    – Charlie
    Commented May 17 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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