I want to record the time between each keystroke (just one key to start with, the ‘A’ key) in millseconds.
After the user finishes his thing he can submit and check out the timings between each key stroke. Like:
1: 500
2: 300
3: 400
4: 500
5: 100
6: 50
7: 50
8: 25
I believe this is possible with Javascript, is it?
Sure:
I added the keycode just in case you wanted it later; it’s not necessary for your exact problem statement.
Clarification from comments discussion:
The
forloop only goes to up totimes.length - 2(sinceiis always strictly less thantimes.length - 1), so there is no issue abouttimes[i+1]being outside the bounds of the array. For example, if you do five key presses and therefore have atimesarray with five elements (indexed from0to4):Then the loop terminates, because setting
ito4triggers the termination condition:Thus,
times[i+1]is always a validly indexed element, becauseiis at most one less than the maximum index.