Mathematica (notebook expression), 248 bytes
DynamicModule[{x={},s=0,t=0},EventHandler[Framed@Dynamic[If[x=={"a"}&&s<1,s=SessionTime[]];Which[x==a,If[t==0,t=SessionTime[]-s];1000t,x==a~Take~Length@x,""<>x,1>0,"Fail"]],Table[{"KeyDown",c}:>x~AppendTo~CurrentValue@"EventKey",{c,a=Alphabet[]}]]]
How it works
DynamicModule[{x={},s=0,t=0},
EventHandler[
Framed@Dynamic[
If[x=={"a"} && s<1,s=SessionTime[]];
Which[
x==a,If[t==0,t=SessionTime[]-s];1000t,
x==a~Take~Length@x,""<>x,
1>0,"Fail"]],
Table[{"KeyDown",c}:>x~AppendTo~CurrentValue@"EventKey",
{c,a=Alphabet[]}]]]
A DynamicModule
with an EventHandler
that responds to lowercase letter keypresses. The variables x
, s
, and t
hold the letters pressed so far, the start time, and the end time, respectively. As soon as we notice x
being equal to {"a"}
, we start the time; we display either the total time spent, or the string built so far, or "Fail"
depending on which condition is met.
We could save another byte with t<1
rather than t==0
if we can assume that nobody is fast enough to type the alphabet in less than one second :)
If you're trying this out in a Mathematica notebook, keep in mind that you have to click inside the frame before your keypresses will be registered. (This is the reason that we need the frame to begin with; if Framed
is not there, then the entire object selected changes when a key is pressed, so it stops being selected and you'd have to click again.)
Fail
without a heading newline? (e.g.abdFail\n
orabd Fail\n
)) \$\endgroup\$Fail
or milliseconds) must be on a new line, like in the example. Most answers already assume this. \$\endgroup\$