Way to log timing of key presses during a timing 'countdown' question | XM Community
Skip to main content

Way to log timing of key presses during a timing 'countdown' question

  • January 30, 2023
  • 2 replies
  • 119 views

Forum|alt.badge.img

Hello,
I was wondering if there was a JavaScript solution available so that during a block with a 5 minute countdown (done with a timing question), each time the participant presses the ENTER key inside a text box within the page, the time of that key-press is recorded in some sort of embedded data variable.
It is specifically the script for recording the timing of each key-press that has me stumped. Any help on this issue would be greatly appreciated!

2 replies

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • January 30, 2023

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 30, 2023

Do something like the following. It will record the times in milliseconds from when the page is ready:
Qualtrics.SurveyEngine.addOnReady(function() {
var start = new Date(), times = [];
jQuery("#"+this.questionId+" input[type=text]").keydown(function(ev) {
if(ev.key==='Enter') times.push(new Date() - start);
});
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
Qualtrics.SurveyEngine.setEmbeddedData("times",times.join(","));
});
});