使用 javascript 使用按键记录 qualtrics 中的反应时间而不前进

Using javascript to record reaction time in qualtrics using keypress without advancing

我是 javascript 的新手,正在学习如何在 qualtrics 中使用它。在我的调查中,我有一个问题设置为显示 1500 毫秒,受访者必须按两个键('S' 或 'D')中的一个来做出回应。我想要的是让 Qualtrics 记录受访者在进入下一个问题之前敲击这些键中的一个需要多长时间,并且 Qualtrics 在按键后不会自动进入下一个问题。

下面的代码允许使用 'S' 或 'D' 键进行响应,并防止问题在按键后自动前进。但是,记录的反应时间始终是问题的持续时间(1500 毫秒),而不是参与者回答所花的时间。如果有人对我如何准确记录按键反应时间有任何想法,将不胜感激!

Qualtrics.SurveyEngine.addOnload(function () {
  this.hideNextButton();
  this.hidePreviousButton();
  var that = this;
  Event.observe(document, 'keydown', function keydownCallback(e) {
    var choiceID = null;
    switch (e.keyCode) {
      case 83: // 'S' was pressed
        choiceID = 1;
        break;
      case 68: // 'D' was pressed
        choiceID = 2;
        break;
    }
    if (choiceID) {
      Event.stopObserving(document, 'keydown', keydownCallback);
      that.setChoiceValue(choiceID, true);
    }
  });
});

请尝试使用以下代码:

Qualtrics.SurveyEngine.addOnload(function () {
  let timeOnLoad = new Date().getTime();
  this.hideNextButton();
  this.hidePreviousButton();
  var that = this;
  Event.observe(document, 'keydown', function keydownCallback(e) {
    var choiceID = null;
    switch (e.keyCode) {
      case 83: // 'S' was pressed
        choiceID = 1;
        break;
      case 68: // 'D' was pressed
        choiceID = 2;
        break;
    }
    if (choiceID) {
      let timeTaken = new Date().getTime() - timeOnLoad;
      console.log(timeTaken);
      Event.stopObserving(document, 'keydown', keydownCallback);
      that.setChoiceValue(choiceID, true);
    }
  });
});

希望对您有所帮助:)

通过查看文档,我想这可以解决问题。

Qualtrics.SurveyEngine.addOnload(function () {
  var startTime = new Date().getTime();
  this.hideNextButton();
  this.hidePreviousButton();
  var that = this;
  Event.observe(document, 'keydown', function keydownCallback(e) {
    var choiceID = null;
    switch (e.keyCode) {
      case 83: // 'S' was pressed
        choiceID = 1;
        break;
      case 68: // 'D' was pressed
        choiceID = 2;
        break;
    }
    if (choiceID) {
      let reactionTime = new Date().getTime() - startTime;
      Event.stopObserving(document, 'keydown', keydownCallback);
      that.setChoiceValue(choiceID, true);
      that.setEmbeddedData('reactionTime', reactionTime);
    }
  });
});

参考:https://s.qualtrics.com/WRAPI/QuestionAPI/classes/Qualtrics%20JavaScript%20Question%20API.html