Reaction time from first keypress | XM Community
Question

Reaction time from first keypress

  • 16 August 2019
  • 1 reply
  • 15 views

Badge +1
Hi there,

I am having trouble capturing the time from page onset to first key press (any key press). Participants have to fill an open text box and I would like to measure the time it takes them to first type something. Participants won't have to click in the box to type, thanks to a script for pre-selecting a text entry, they can just start typing.

The traditional timer can register the time until a first click, but not until a key press.
I have looked at every other discussion about how to implement reaction time with Javascript, but nothing seems to do the trick.

Any help will be really appreciated. Thanks in advance.

1 reply

Userlevel 5
Badge +7
Hey @dcousineau,
I'm not sure how 'dirty' of a solution is acceptable to you, but the first thing that comes to mind is a JavaScript loop that adds 1 to an `int secondsElapsed` and then sleeps 1 second until the user hits their first key. This would only give you a whole second as the finest point of measurement, always rounding down, but I thought it might enough for you. You could then use the Qualtrics API setEmbeddedData to write that value back to the survey to view the result in the Data& Analysis tab.

A cleaner solution by far would be OnPageLoad, call a new Date() and assign to StartTime variable, then add a keydown eventListener to the pre-selected textbox and call Date.now assigned to EndTime. You can then simply subtract the 2 times, formatted to your desire. In essence, you'd be creating your own form of a stopwatch.

Leave a Reply