[Question]
  [
Your task is to make a program that measures how fast you can type the letters of the English alphabet.
* The program shall only accept lowercase letters `a` to `z` in alphabetical order.
* Each letter is echoed as typed on the same line (without new line or any other separators between letters).
* If you type an invalid character the program shall output `Fail` *on a new line* and exit.
* If you type all 26 letters the program shall, *on a new line*, output the time in milliseconds it took from the first to the last letter and exit.
* The timer starts when you type the first letter, `a`.
Example outputs:
```
b
Fail
abcdefgg
Fail
abcdefghijklmnopqrstuvwxyz
6440
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.
  
[Answer]
## HTML (JavaScript (ES6)), ~~129~~ ~~126~~ 117 bytes
```
<input id=i onfocus=l=0,n=Date.now onkeypress=event.which-97-l?i.outerHTML='Fail':24<l?i.outerHTML=n()-t:t=l++?t:n()>
```
Click in the input and start typing! Also, my typing sucks; I take about 5 seconds even with practice. Edit: Saved 2 bytes thanks to @HermanLauenstein by switching language. Saved 3 bytes thanks to @qw3n. Saved 9 bytes thanks to @tsh.
[Answer]
# [6502 machine code](https://en.wikibooks.org/wiki/6502_Assembly) (C64 PAL), 189 165 bytes
```
00 C0 A9 17 8D 18 D0 A9 40 85 FE E6 FE 20 E4 FF F0 FB 20 D2 FF C5 FE 38 D0 38
C9 5A 18 F0 33 C9 41 D0 E8 A9 00 85 FC 85 FD A9 18 85 FB A9 7F 8D 0D DD A9 7F
8D 18 03 A9 C0 8D 19 03 A9 D8 8D 04 DD A9 03 8D 05 DD A9 01 8D 0E DD A9 81 8D
0D DD D0 B9 A9 7F 8D 0D DD A9 47 8D 18 03 A9 FE AD 19 03 CE 0E DD B0 14 A9 0D
20 D2 FF A4 FC A5 FD 20 91 B3 20 DD BD A9 01 A8 D0 04 A9 9D A0 C0 4C 1E AB 48
AD 0D DD 29 01 F0 14 E6 FC D0 02 E6 FD C6 FB D0 0A A9 18 85 FB CE 0E DD EE 0E
DD 68 40 0D C6 41 49 4C 00
```
* -24 bytes by inlining functions and not caring for other CIA2 interrupts
**[Online demo](https://vice.janicek.co/c64/#%7B%22controlPort2%22:%22joystick%22,%22primaryControlPort%22:2,%22keys%22:%7B%22SPACE%22:%22%22,%22RETURN%22:%22%22,%22F1%22:%22%22,%22F3%22:%22%22,%22F5%22:%22%22,%22F7%22:%22%22%7D,%22files%22:%7B%22fasttype.prg%22:%22data:;base64,AMCpF40Y0KlAhf7m/iDk//D7INL/xf440DjJWhjwM8lB0OipAIX8hf2pGIX7qX+NDd2pf40YA6nAjRkDqdmNBN2pA40F3akBjQ7dqYGNDd3Qual/jQ3dqUeNGAOp/q0ZA84O3bAUqQ0g0v+k/KX9IJGzIN29qQGo0ASpnaDATB6rSK0N3SkB8BTm/NAC5v3G+9AKqRiF+84O3e4O3WhADcZBSUwA%22%7D,%22vice%22:%7B%22-autostart%22:%22fasttype.prg%22%7D%7D)** (Usage: `sys49152`)
[![Screenshot](https://i.stack.imgur.com/O1aly.png)](https://i.stack.imgur.com/O1aly.png)
---
### Explanation:
This would be a tiny program if it wasn't for the problem of an exact measurement of milliseconds on the C64. The system interrupt occurs *roughly* 60 times per second, which isn't even close. So we have to use a hardware timer here that gets its input ticks from the system clock.
On a PAL machine, the system clock is exactly 985248 Hz. Initializing the timer to 985 therefore gives something *close* to millisecond ticks, but it's a bit too fast, we'd have to count 986 cycles for every fourth tick, or hold the timer for a single cycle. This isn't possible, but we can hold the timer for 6 cycles with the sequence `DEC $DD0E`, `INC $DD0E`: `$DD0E` is the timer control register with bit 0 switching it on and off, and both instructions take 6 cycles, so the exact writes that stop and start the timer are exactly 6 cycles apart. Therefore we have to execute this sequence every 6\*4 = 24th tick. This still isn't *absolutely* exact, the timer will lag 1 millisecond behind after 8 minutes and 12 seconds, but it's probably good enough -- compensating for that one would take a *lot* of code.
**edit**: The start value for the timer must be 984, not 985, because these timers fire "on underflow", so a value of 0 will count one more cycle before firing. Code fixed, byte count unchanged.
Here's the commented disassembly listing:
```
         00 C0       .WORD $C000        ; load address
.C:c000  A9 17       LDA #$17           ; mode for upper/lower text
.C:c002  8D 18 D0    STA $D018          ; set in graphics chip
.C:c005  A9 40       LDA #$40           ; initialize expected character
.C:c007  85 FE       STA $FE            ; to 'a' - 1
.C:c009   .mainloop:
.C:c009  E6 FE       INC $FE            ; increment expected character
.C:c00b   .getchar:
.C:c00b  20 E4 FF    JSR $FFE4          ; read character from keyboard
.C:c00e  F0 FB       BEQ .getchar       ; until actual character entered
.C:c010  20 D2 FF    JSR $FFD2          ; output this character
.C:c013  C5 FE       CMP $FE            ; compare with expected
.C:c015  38          SEC                ; set carry as marker for error
.C:c016  D0 38       BNE .result        ; wrong character -> output result
.C:c018  C9 5A       CMP #$5A           ; compare with 'z'
.C:c01a  18          CLC                ; clear carry (no error)
.C:c01b  F0 33       BEQ .result        ; if 'z' entered, output result
.C:c01d  C9 41       CMP #$41           ; compare with 'a'
.C:c01f  D0 E8       BNE .mainloop      ; if not equal repeat main loop
.C:c021  A9 00       LDA #$00           ; initialize timer ticks to 0
.C:c023  85 FC       STA $FC
.C:c025  85 FD       STA $FD
.C:c027  A9 18       LDA #$18           ; counter for adjusting the timer
.C:c029  85 FB       STA $FB
.C:c02b  A9 7F       LDA #$7F           ; disable all CIA2 interrupts
.C:c02d  8D 0D DD    STA $DD0D
.C:c030  A9 7F       LDA #<.timertick   ; set NMI interrupt vector ...
.C:c032  8D 18 03    STA $0318
.C:c035  A9 C0       LDA #>.timertick
.C:c037  8D 19 03    STA $0319          ; ... to our own timer tick routine
.C:c03a  A9 D9       LDA #$D8           ; load timer with ...
.C:c03c  8D 04 DD    STA $DD04
.C:c03f  A9 03       LDA #$03
.C:c041  8D 05 DD    STA $DD05          ; ... 985 (-1) ticks (see description)
.C:c044  A9 01       LDA #$01           ; enable timer
.C:c046  8D 0E DD    STA $DD0E
.C:c049  A9 81       LDA #$81           ; enable timer interrupt
.C:c04b  8D 0D DD    STA $DD0D
.C:c04e  D0 B9       BNE .mainloop      ; repeat main loop
.C:c050   .result:
.C:c050  A9 7F       LDA #$7F           ; disable all CIA2 interrupts
.C:c052  8D 0D DD    STA $DD0D
.C:c055  A9 47       LDA #$47           ; set NMI interrupt vector ...
.C:c057  8D 18 03    STA $0318
.C:c05a  A9 FE       LDA #$FE
.C:c05c  AD 19 03    LDA $0319          ; ... back to system default
.C:c05f  CE 0E DD    DEC $DD0E          ; disable timer
.C:c062  B0 14       BCS .fail          ; if carry set, output fail
.C:c064  A9 0D       LDA #$0D           ; load newline
.C:c066  20 D2 FF    JSR $FFD2          ; and output
.C:c069  A4 FC       LDY $FC            ; load timer value in
.C:c06b  A5 FD       LDA $FD            ; A and Y
.C:c06d  20 91 B3    JSR $B391          ; convert to float
.C:c070  20 DD BD    JSR $BDDD          ; convert float to string
.C:c073  A9 01       LDA #$01           ; load address of
.C:c075  A8          TAY                ; string buffer
.C:c076  D0 04       BNE .out           ; and to output
.C:c078   .fail:
.C:c078  A9 9D       LDA #<.failstr     ; load address of "Fail" string
.C:c07a  A0 C0       LDY #>.failstr     ; in A and Y
.C:c07c   .out:
.C:c07c  4C 1E AB    JMP $AB1E          ; done; OS routine for string output
.C:c07f   .timertick:
.C:c07f  48          PHA                ; save accu
.C:c080  AD 0D DD    LDA $DD0D          ; load interrupt control register
.C:c083  29 01       AND #$01           ; to know whether it was a timer NMI
.C:c085  F0 14       BEQ .tickdone      ; if not -> done
.C:c087  E6 FC       INC $FC            ; increment timer ticks ...
.C:c089  D0 02       BNE .adjusttick
.C:c08b  E6 FD       INC $FD            ; high byte only on overflow
.C:c08d   .adjusttick:
.C:c08d  C6 FB       DEC $FB            ; decrement counter for adjusting
.C:c08f  D0 0A       BNE .tickdone      ; not 0 yet -> nothing to do
.C:c091  A9 18       LDA #$18           ; restore counter for adjusting
.C:c093  85 FB       STA $FB
.C:c095  CE 0E DD    DEC $DD0E          ; halt timer for exactly
.C:c098  EE 0E DD    INC $DD0E          ; 6 cycles
.C:c09b   .tickdone:
.C:c09b  68          PLA                ; restore accu
.C:c09c  40          RTI
.C:c09d   .failstr:
.C:c09d  0D C6 41    .BYTE $0D,"Fa"
.C:c0a0  49 4C 00    .BYTE "il",$00
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + coreutils, ~~103~~ ~~99~~ 98 bytes
```
for((;c==p%26;r=`date +%s%3N`-(s=s?s:r),c=62#$c-9,p++))
{
read -N1 c
}
((c==p))||r=Fail
echo "
$r"
```
Must be run in a terminal.
### Test run
```
$ bash type.sh
abcdefghijklmnopqrstuvwxyz
3479
$ bash type.sh
abcz
Fail
$ bash type.sh 2>&- # typing '@' would print to STDERR
ab@
Fail
$ bash type.sh
A
Fail
```
[Answer]
# Python 2 + [getch](https://pypi.python.org/pypi/getch), 116 bytes
```
import time,getch
t=[i+97-ord(getch.getche())and exit("Fail")or time.time()for i in range(26)]
print(t[-1]-t[0])*1e3
```
Thanks to ovs and ElPedro for fixing the code and saving 57 bytes.
[Answer]
# [Pascal (FPC)](https://www.freepascal.org/), 176 bytes
```
Uses CRT,SysUtils;Var c:char;a:Real;Begin
for c:='a'to'z'do
if c=ReadKey then
begin Write(c);if c='a'then a:=Now;end
else
begin
Write('Fail');Halt;end;Write((Now-a)*864e5)
End.
```
[Try it online!](https://tio.run/##Jcu9DoIwGIXhvVfRrWLESY2hYdFoTEwcVHT@bL9KtbZI6w/cPIKs73lOAV6AiVUhmibz6OlyfxwdKp8FbTw/QUlFInIoOSR7BMMXeNWWKNf1lAELjtVMOqIVFWkr5BYrGnK05NJJei51wIGI@B90h3ajkKQ79@FoJUHjsbekt2wN2rCIb8CETvA@D9pDDNFwPpvgNCIrK8dNAxchUV1zfbubh3XFs/Th9f58q/oH "Pascal (FPC) – Try It Online")
Some tricks used in code for golfing:
* Use `Real` as a shorter alternative to `TDateTime`, because as defined [here](https://www.freepascal.org/docs-html/rtl/system/tdatetime.html), `TDateTime` = `Double`, which is floating-point type.
* Instead of using `MilliSecondsBetween` for calculating time gap, this code multiply the difference between two floating-point values by `864e5`, which works because of the way Free Pascal encode `TDateTime` described [here](https://www.freepascal.org/~michael/articles/datetime/datetime.pdf).
Note:
* `ReadKey` function doesn't actually print the key on the console, so manual writing to console with `Write(c)` is necessary.
* TIO get a score near `0` for typing the alphabet for obvious reason.
* The program prints time in floating-point notation, I guess that's allowed.
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), 35 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
"ζ¦F‘→I
]I!}Su[I:lzm≠?■Fail←z=?Suκ←
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JTIyJXUwM0I2JUE2RiV1MjAxOCV1MjE5MkklMEElNURJJTIxJTdEU3UlNUJJJTNBbHptJXUyMjYwJTNGJXUyNUEwRmFpbCV1MjE5MHolM0QlM0ZTdSV1MDNCQSV1MjE5MA__) - click run, and enter the alphabet in the input box. Note that it may be a little laggy because SOGL only pauses for input every 100 executed tokens (and SOGL is quite slow). If that bothers you, run `sleepBI=true` in the console.
**note:** don't run this in the compatibility mode - it'll just loop forever.
Explanation:
```
"ζ¦F‘    push "inputs.value" (yes, that is a word in SOGLs english dictionary)
     →   execute as JS, pushing the inputs contents
      I  named function I
]  }                do while POP is truthy
 I                    execute I
  !                   negate it - check if it's empty
    Su              push the current milliseconds since start
[                   loop
 I                    execute I
  :                   duplicate the result
   l                  let its length
    zm                mold the alphabet to that size
      ≠?              if that isn't equal to one of the result copies
        ■Fail           push "Fail"
             ←          and exit, implicitly outputting that
              z=?     if the other copy is equal to the alphabet
                 Su     push the milliseconds since start
                   κ    subtract the starting milliseconds from that
                    ←   and exit, implicitly outputting the result
```
[Answer]
# Java, ~~404~~ ~~388~~ ~~354~~ ~~348~~ ~~320~~ 318 bytes
```
import java.awt.*;import java.awt.event.*;interface M{static void main(String[]a){new Frame(){{add(new TextArea(){{addKeyListener(new KeyAdapter(){long t,i=64;public void keyPressed(KeyEvent e){t=t>0?t:e.getWhen();if(e.getKeyChar()!=++i|i>89){System.out.print(i>89?e.getWhen()-t:"Fail");dispose();}}});}});show();}};}}
```
And here I thought Java Console was already verbose..  
Since Java has no way to raw listen for key-presses in the Console a.f.a.i.k., I use a GUI with `java.awt`.
-78 bytes thanks to *@OlivierGrégoire*.
**Explanation:**
```
import java.awt.*;                 // Required import for Frame and TextField
import java.awt.event.*;           // Required import for KeyAdapter and KeyEvent
interface M{                       // Class
  static void main(String[]a){     //  Mandatory main-method
    new Frame(){                   //   Create the GUI-Frame
      {                            //    With an initialization-block
        add(new TextArea(){        //     Add an input-field
          {                        //      With it's own initialization-block
            addKeyListener(new KeyAdapter(){
                                   //       Add a KeyAdapter to the input-field
              long t,              //        Long to save the time
                   i=64;           //        Previous character, starting at code of 'a' -1
              public void keyPressed(KeyEvent e){ 
                                   //        Override the keyPressed-method:
                t=t>0?             //         If `t` is already set:
                   t               //          Leave it the same
                  :                //         Else:
                   e.getWhen();    //          Save the current time (== start the timer)
                if(e.getKeyCode()!=++i
                                   //         As soon as an incorrect character is pressed,
                   |i>89){         //         or we've reached 'z':
                  System.out.print(i>89?
                                   //          If we're at 'z':
                    e.getWhen()-t  //           Print the end-time in ms to the Console
                   :               //          Else (an incorrect character was pressed)
                    "Fail");       //           Print "Fail" to the Console
                  dispose();}      //          And exit the application
              }                    //        End of keyPressed-method
            });                    //       End of KeyAdapter
          }                        //      End of input-field initialization-block
        });                        //     End of input-field
        show();                    //     Initially show the Frame
      }                            //    End of Frame initialization-block
    };                             //   End of Frame 
  }                                //  End of main-method
}                                  // End of class
```
**Example gif of success:** (Yes, I type the alphabet pretty slowly here..)  
*Note: This is an old gif. Current version no longer prints key-presses to Console. And it no longer prints the time with digits after the decimal point.*
[![enter image description here](https://i.stack.imgur.com/qYPs4.gif)](https://i.stack.imgur.com/qYPs4.gif)  
**Example gif of fail:**  
*Note: This is an old gif. Current version no longer prints key-presses to Console.*
[![enter image description here](https://i.stack.imgur.com/pgIAE.gif)](https://i.stack.imgur.com/pgIAE.gif)
[Answer]
# C# (.NET Core), ~~245 + 13~~ ~~183 + 41~~ 177 + 41 bytes
+41 bytes for `using System;using static System.Console`.
Untested since I am on mobile and this does not run on TIO.
```
n=>{int c=ReadKey().KeyChar,x=0;try{if(c!=97)x/=x;var s=DateTime.Now;while(c<149)if(ReadKey().KeyChar!=c++)x/=x;Write((DateTime.Now-s).TotalMilliseconds);}catch{Write("Fail");}}
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 184+13=197 173+13=186 bytes
```
()=>{var s=DateTime.Now;var i=97;while(i<123&&Console.ReadKey().KeyChar==i)if(i++<98)s=DateTime.Now;Console.Write(i>122?$"\n{(DateTime.Now-s).TotalMilliseconds}":"\nFail");}
```
[Try it online!](https://tio.run/##XY5BS8NAFITP3V/xCFJ2KQ00HrRutxIqXqRSasGLl2XztA@2uyVvbSghvz0mB0G8zMDwzTCO5y7W2H8zhS94u3LCkxbOW2bYtaJ0iWKAEkwvlVm3F1sDmyeb8EAnzF9jo8eIzPJON0fyKGm1KG6n000MHD3me7TVC16lygfdHG1tDCn6lDSbrZb36t/Wb@u9pjRMrRdF8XiTfYRW/sXmrPJDTNZvyXtidDFU3GUPA/hsyWdKd70WgpNN5OASqYKtpSCVaMVkvHsGAwEb2EmlxeScl6N3out/AA "C# (.NET Core) – Try It Online")
Unfortunately TIO can't run this, but it's handy for getting byte count.
+13 for `using System;`
-1 by changing `i==123` to `i>122`. I was tempted to make this `i>'z'`.
### Acknowledgements
-10 bytes thanks to @raznagul
### Ungolfed
```
()=>{
    var s=DateTime.Now;
    var i=97;
    while(i<123&&Console.ReadKey().KeyChar==i)
        if(i++<98)
            s=DateTime.Now;
    Console.Write(i>122?
        $"\n{(DateTime.Now-s).TotalMilliseconds}":
        "\nFail"
    );
} 
```
[Answer]
# Node.js, 240 213 bytes
```
require('readline',{stdin:i,stdout:o,exit:e}=process).emitKeypressEvents(i)
w=s=>o.write(s)
n=0
i.on('keypress',c=>w(c)&&c.charCodeAt()-97-n?e(w(`
Fail`)):!n++?s=d():n>25&&e(w(`
`+(d()-s)))).setRawMode(d=Date.now)
```
EDIT: Saved 27 bytes thanks to Jordan
Ungolfed version:
```
const readline = require('readline')
let index = 0
let start
readline.emitKeypressEvents(process.stdin)
process.stdin.setRawMode(true)
process.stdin.on('keypress', character => {
  process.stdout.write(character )
  // Lookup character in ASCII table
  if (character !== String.fromCharCode(97 + index) {
    process.stdout.write('\nFail')
    process.exit()
  }
  index++
  if (index === 1) {
    start = Date.now()
  }
  if (index === 26) {
    process.stdout.write('\n' + (Date.now() - start))
    process.exit()
  }
})
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 303 bytes
Works on \*nix systems. Standalone code removing the current terminal's canonical mode to allow reading characters without waiting for newlines:
/!\ Running this program will make the terminal almost unusable.
```
#import <stdlib.h>
#import <termios.h>
#define x gettimeofday(&t,0)
#define r t.tv_sec*1000+t.tv_usec/1000
c,i=97;main(){long s=0;struct termios n;struct timeval t;cfmakeraw(&n);n.c_lflag|=ECHO;tcsetattr(0,0,&n);for(;i<'d';){c=getchar();if(c!=i++)puts("\nFail"),exit(0);x;s=s?:r;}x;printf("\n%ld",r-s);}
```
**Ungolfed and commented:**
```
// needed in order to make gcc aware of struct termios
// and struct timeval sizes
#import <stdlib.h>
#import <termios.h>
// gets the time in a timeval structure, containing
// the number of seconds since the epoch, and the number
// of µsecs elapsed in that second
// (shorter than clock_gettime)
#define x gettimeofday(&t,0)
// convert a timeval structure to Epoch-millis
#define r t.tv_sec*1000+t.tv_usec/1000
// both integers
// c will contain the chars read on stdin
// 97 is 'a' in ASCII
c,i=97;
main(){
  long s=0; // will contain the timestamp of the 1st char entered
  struct timeval t; // will contain the timestamp read from gettimeofday
  // setting up the terminal
  struct termios n;
  cfmakeraw(&n);//create a raw terminal configuration
  n.c_lflag|=ECHO;//makes the terminal echo each character typed
  tcsetattr(0,0,&n);//applies the new settings
  // from 'a' to 'z'...
  for(;i<'{';){
    // read 1 char on stdin
    c=getchar();
    // if int value of the input char != expected one => fail&exit
    if(c!=i++)puts("\nFail"),exit(0);
    // macro x: get current timestamp
    x;
    // if not already set: set starting timestamp
    s=s?:r;
  }
  // get end of sequence timestamp
  x;
  // prints the end-start timestamps difference
  printf("\n%ld",r-s);
}
```
**Alternative solution (218 bytes):**
If configuring the terminal beforehand is allowed, then we can get rid of the portion of code handling that part.
Here is the same code without terminal manipulation:
```
#import <stdlib.h>
#define x gettimeofday(&t,0)
#define r t.tv_sec*1000+t.tv_usec/1000
c,i=97;main(){long s=0;struct timeval t;for(;i<'{';){c=getchar();if(c!=i++)puts("\nFail"),exit(0);x;s=s?:r;}x;printf("\n%ld",r-s);}
```
To make it work:
```
$ gcc golf.c
$ stty -icanon
$ a.out
```
**runtime example:**
[![enter image description here](https://i.stack.imgur.com/zs80w.gif)](https://i.stack.imgur.com/zs80w.gif) 
[Answer]
# Commodore BASIC v2 - 113 bytes
Capital letters must be shifted.  
Thanks to Felix Palmen for pointing out some typos, specs  
[try it](https://vice.janicek.co/c64/#%7B%22controlPort2%22:%22joystick%22,%22primaryControlPort%22:2,%22keys%22:%7B%22SPACE%22:%22%22,%22RETURN%22:%22%22,%22F1%22:%22%22,%22F3%22:%22%22,%22F5%22:%22%22,%22F7%22:%22%22%7D,%22files%22:%7B%22type.prg%22:%22data:;base64,AQgRCAAARLI2NDqZxygxNCkALQgBAJGrKEayMjYpiTU6oUEkOotBJLIiIqcxAEAIAgCLqCirtChGKSmnVLJUSQBYCAMARrJGqjE6i0Eks7HHKESqRimnNgBkCAQAmUEkOzqJMQB8CAUAmTqZKFRJq1QprTYwrDEwMDA6gACICAYAmSLGQUlMIgAAAA==%22%7D,%22vice%22:%7B%22-autostart%22:%22type.prg%22%7D%7D)
```
0d=64
1on-(f=26)gO5:gEa$:ifa$=""tH1
2iff=0tHt=ti
3f=f+1:ifa$<>cH(d+f)tH6
4?cH(14)a$;:gO1
5?:?(ti-t)/60*1000:eN
6?"Fail"
```
[Answer]
# 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.)
[Answer]
# MSX-BASIC, 126 characters
```
1C=97:GOSUB3:TIME=0
2IFASC(C$)<>CTHEN?"Fail":ENDELSEIFC=122THEN?TIME*20:ENDELSEC=C+1:GOSUB3:GOTO2
3C$=INKEY$:IFC$=""GOTO3
4RETURN
```
`TIME` is an internal MSX-BASIC variable that increases by one every 20 milliseconds.
[Answer]
# Perl 5, ~~79~~ 93 +31 (-MTerm::ReadKey -MTime::HiRes=time) bytes
```
$|=1;map{ReadKey eq$_||exit print"
Fail";$s||=time}a..z;print$/,0|1e3*(time-$s)
```
`$|=1` is not sufficient to set terminal in raw mode, `stty -icanon` should be run before or
```
ReadMode 3;map{ReadKey eq$_||exit print"
Fail";print;$s||=time}a..z;print$/,0|1e3*(time-$s)
```
to see characters in the terminal after running command : `stty echo` or `stty echo icanon`
[Answer]
# [APL (Dyalog)](https://www.dyalog.com), [SBCS](https://github.com/abrudz/SBCS), 114 153 bytes
Using a GUI form to handle keypress events:
```
t←⍬
a←819⌶⎕A
f←{⍬≡t:f ⍵⊣t⊢←⎕AI⋄⊃a≠⍞←3⊃⍵:⎕EX⎕A⊣⎕←'Fail'⋄'z'=a~←⊃a:⎕←3⊃⎕AI-t}
⎕DQ⎕A⎕WC'Form'('Event' 'KeyPress' 'f')
```
(Golfed by [Adám](https://codegolf.stackexchange.com/users/43319/ad%c3%a1m); I think it would be odd for him to be awarding a bounty for an answer which is now mostly his golf rewrite, so that's here, and my original is below. This version handles the "exit on failure" part of the spec, too.]
```
t←⍬
a←(819⌶)⎕A
∇w
'W'⎕WC'Form'('Event' 'KeyPress' 'f')
⎕DQ'W'
∇
∇f e
{26=≢a:t⊢←⎕TS}⍬
{e[3]=1↑a:{⍞←1↑a⋄a⊢←1↓a}⍬⋄⎕←'Fail'}⍬
{0=≢a:⎕←60 60 1e3⊥4↓⎕TS-t}⍬
∇
w
```
Image of it (the first posted version) in use, Dyalog APL 17.1:
[![Animated screen capture of this code working in Dyalog APL 17.1](https://i.stack.imgur.com/cTSRl.gif)](https://i.stack.imgur.com/cTSRl.gif)
---
### Explanation.
It's a function `w` which loads a GUI form and adds an event handler to it, and starts listening for events, and the call back which handles the alphabet.
Lambda functions are used to get guard pattern matching, instead of longer `:If ⋄ cond ⋄ code ⋄ :Else ⋄ code ⋄ :EndIF` syntax. Guards are `{cond: code}` pattern, and the `{}⍬` pattern is calling a function on an empty numeric vector just to make it run
```
t←⍬  ⍝ Variable for the time of starting typing
a←(819⌶)⎕A  ⍝ Variable for lowercase alphabet, 
               cast from uppercase with I-beam 819
⍝ Function "w" makes window of type 'Form', called 'W', with event handler.
⍝ Callback function "f", and starts event loop.
∇w
'W'⎕WC'Form'('Event' 'KeyPress' 'f')
⎕DQ'W'
∇
⍝ event handler function "f" takes event "e"
∇f e
{26=≢a:t⊢←⎕TS}⍬    ⍝ lambda function (dfn)
                   ⍝ checks if there are 26 letters,
                   ⍝ (i.e. started typing) starts the timer.
                   ⍝ "t" is initialised first, for global scoping.
{e[3]=1↑a:{⍞←1↑a⋄a⊢←1↓a}⍬⋄⎕←'Fail'}⍬ ⍝ guard, if event[3] (key pressed)
                                     ⍝ is the next alphabet letter (first of "a")
                                     ⍝ print 1 from "a", drop 1 from "a"
                                     ⍝ else print "Fail".
{0=≢a:⎕←60 60 1e3⊥4↓⎕TS-t}⍬  ⍝ guard, if all the letters are gone,
                             ⍝ subtract current timestamp from stored,
                             ⍝ drop 4 elements (year, month, day, hour)
                             ⍝ base-convert min, sec, ms to pure ms
                             ⍝ and print.
∇
⍝ run it by calling function "w"
w
```
[Answer]
# C#, 154 152 + 13 = 165 bytes
Saved 2 bytes thanks to Ayb4btu's comments
```
x=>{
  long t=0,c=97;
  for(;Console.ReadKey().KeyChar==c++&&c<123;t=t<1?DateTime.Now.Ticks:t);
  Console.Write(c>122?"\n"+(DateTime.Now.Ticks-t)/1e4:"\nFail");
}
```
The code above has whitespace to make it fit in SE without a scrollbar. Whitespace isn't part of the byte count
and 13 bytes for `using System;`
It's similar to Ayb4btu's version but with the following differences:
* Storing datetime as a long, allows us to make `c` a long also, and short cut the declaration
* Loop doesn't need a separate break
* It's not actually shorter to use `$"interpreted strings"` versus adding a needed "\n" onto the milliseconds to make it a string for the inline if
* Using a `for` loop sometimes allows us to save chars over a while, though I think this one wouldn't save over the equivalent `while`
From Ayb4btu:
* `s=s==0` can become `s=s<1`, and `c==123` can become `c>122`
### Ungolfed
```
long t=0,c=97;
for (;                                         //no loop vars declared
  Console.ReadKey().KeyChar == c++ && c < 123; //loop test
  t = t < 1 ? DateTime.Now.Ticks : t          //post-loop assigns
) ;                                            //empty loop body!
//now just need to turn ticks into millis, 10,000 ticks per millis
Console.Write(c>122?"\n"+(DateTime.Now.Ticks-t)/1e4:"\nFail");
```
[Answer]
# [Aceto](https://github.com/aceto/aceto), 70 bytes
```
d'|d 't9
$z=p zp1
!=   >#v
d,   1 +
cTpaXpn3
Io$'p"*F
|'!=ilnu
@ad,aF"
```
I start by setting a catch mark and mirroring horizontally(`@|`), if the value on the stack is truthy. It isn't initially, and later always will be. We will jump back here later if a wrong key is entered.
Next, we push an a on the stack (`'a`), then we duplicate it and read a single character from the user (`d,`). If the two characters are not equal (`=!`), we "crash" (`$`) and jump back to the catch mark.
Otherwise, we push another "a" and print it, then we set the current time (`'apT`).
Then we enter our "main loop": We "increment" the current character and "increment" the character (`'apToIc`), then we duplicate it, read a new character, compare it, and "crash" if it the characters aren't identical (`d,=!$`).
If we didn't crash, we compare the current character to "z" (`d'z=|`), if it isn't equal, we print the character, then we push a 1 and jump "conditionally" (in this case: always) to the only `o` in the code (the begin of our main loop).
If it was equal to z, we mirrored horizontally to some empty space on top. We print "z", then push the current time (minus the starting time; `t`) and then multiply the number 1000 (gotten by raising 10 to the third power; `91+3F`) by it (because we get seconds, not milliseconds). Then we print a newline, the time, and exit (`pX`).
If we ever crash (bad input by the user), we jump all the way to the beginning. Since we will now have some truthy value on the stack, we will mirror horizontally onto the `u`, which reverses the direction we're moving in. `n` prints a newline character, then we push `"Fail"` on the stack, print it, and exit (`pX`).
[Answer]
# Processing.org ~~133~~ 142
first code didn't exit
```
char k=97;int m;void draw(){if(key==k){m=m<1?millis():m;print(key=k++,k>122?"\n"+(millis()-m):"");}if(m>0&&key!=k-1){print("\nFail");exit();}}
```
[Answer]
# GCC, windows, 98 bytes
```
t;main(i){for(;i++<27;t=t?:clock())if(95+i-getche())return puts("\nFail");printf("\n%d",clock()-t);}
```
Requires no instantly input for the first key
[Answer]
**Ruby: 194 bytes**
```
require 'io/console'
a=[*"a".."z"]
c=0
s=
loop do
i=STDIN.getch
if i==a[c]
print i
s=Time.now if i=='a'
else
puts "\nFail"
exit
end
if i=='z'
puts "\n"+((Time.now-s)*1000).to_s
exit
end
c+=1
end
```
[Answer]
# Python 3, 107 bytes
```
from time import*;x=time();a=input();print((time()-x)*1000 if a=="abcdefghijklmnopqrstuvwxyz" else "Fail");
```
Outputs a floating point number. Relies on lowercase alphabet.
[Answer]
# Java (Android), 709 bytes
> 
> And here I thought Java Console was already verbose.
> 
> 
> 
*Imagine complaining about AWT* :omegalul:
```
package a;import android.widget.*;import android.text.*;public class Z extends android.app.Activity{long g;long f(){return System.currentTimeMillis();}public void onCreate(android.os.Bundle b){super.onCreate(b);EditText t=new EditText(this);t.setSingleLine();t.setInputType(144);t.addTextChangedListener(new TextWatcher(){public void beforeTextChanged(CharSequence s,int a,int b,int c){if(g<1)g=f();}public void onTextChanged(CharSequence s,int a,int b,int c){}public void afterTextChanged(Editable s){}});t.setOnEditorActionListener((x,y,z)->{t.setError((""+t.getText()).equals("abcdefghijklmnopqrstuvwxyz")?f()-g+"":"Fail");return true;});addContentView(t,new android.view.ViewGroup.LayoutParams(-1,-2));}}
```
Commented version:
```
// Android requires all Activities to be in a package.
package a;
// EditText
import android.widget.*;
// TextWatcher, Editable
import android.text.*;
// just use full package names for the rest
// yes, we need this entire signature.
public class Z extends android.app.Activity {
    // timer
    long g;
    // Wrapper because it is shorter than calling this behemoth
    // Gets the current time
    long f() {
        return System.currentTimeMillis();
    }
    // Activity entry point
    public void onCreate(android.os.Bundle b) {
        super.onCreate(b);
        // Android Studio doesn't have var. They abandoned Java 10 in favor of Kotlin.
        //  geeeeeeeeee I wonder why ANYone would abandon programming for Android in Java... :P
        EditText t = new EditText(this);
        // This sets the enter key to a submit key, allowing us to catch OnEditorAction 
        t.setSingleLine();
        // no autocomplete 4 u
        // InputType.VISIBLE_PASSWORD
        t.setInputType(144);
        // The main reason this is so verbose is because the requirement needs us to start
        // timing on the first character TYPED. It would be much easier to add an onClick or onFocus
        // listener instead, but nooooo. :(
        t.addTextChangedListener(new TextWatcher() {
            // why
            public void beforeTextChanged(CharSequence s, int a, int b, int c) {
                // Start our timer the first time the user types something.
                if (g < 1) g = f();
            }
            // three
            public void onTextChanged(CharSequence s, int a, int b, int c) {
            }
            // methods?
            public void afterTextChanged(Editable s) {
            }
        });
        // When they hit submit, verify using the obvious way.
        // I _may_ be able to verify in TextWatcher, but TextWatcher is not char by char. IDK, I haven't experimented with it yet.
        t.setOnEditorActionListener((x, y, z) -> {
            // Show the result via setError, which is on a new line. :)
            t.setError(("" + t.getText()).equals("abcdefghijklmnopqrstuvwxyz") ? f() - g + "" : "Fail");
            return true;
        });
        // Append to the root view.
        // -1 == LayoutParams.MATCH_PARENT
        // -2 == LayoutParams.WRAP_CONTENT
        addContentView(t, new android.view.ViewGroup.LayoutParams(-1, -2));
    }
}
```
<https://streamable.com/7xb1xl>
Edit: I have gotten very good at this by the way, [look at my mad skills.](https://streamable.com/8sx6t3)
]