使用javascript记录使用keypress的反应时间而无需前进

时间:2018-02-08 06:07:56

标签: javascript jquery qualtrics

我是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);
    }
  });
});

2 个答案:

答案 0 :(得分:1)

请尝试使用以下代码:



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);
    }
  });
});




希望有所帮助:)

答案 1 :(得分:0)

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

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