4
$\begingroup$

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

{{"H",0},{"e",100},{"l",107},{"l",25},{"o",125}}

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.

$\endgroup$

1 Answer 1

9
$\begingroup$

Here is a minimal implementation using EventHandler.

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

enter image description here

$\endgroup$
1
  • $\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
    Feb 22 at 19:31

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.