How can I add a keydown function to qualtrics?

2019-09-05 02:56发布

First, thanks for reading this post.

I am trying to force participants to read several pictures for 30 seconds each. For some specific pictures, participants are asked to press "K." I wonder how I can record if participants correctly press "K" for the assigned pictures and mistakenly press "K" while seeing those unassigned pictures.

I used the two lines to remove the previous/next page buttons. Participants can automatically advance to the next screen after 30 seconds.

this.hideNextButton();
this.hidePreviousButton();

I also tried to used the below function and send 30 seconds to delay submit. However, this code does not work.

this.hideNextButton();
this.hidePreviousButton();

var that = this;

Event.observe(document, 'keydown', function keydownCallback(e) {
var choiceID = null;
switch (e.keyCode) {
case 74: // 'j' was pressed
  choiceID = 1;
  break;
case 75: // 'k' was pressed
  choiceID = 2;
  break;
}

if (choiceID) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
}
});

Thank you again!

1条回答
狗以群分
2楼-- · 2019-09-05 03:12

Ryan,

I also saw your post on the Qualtrics LinkedIn Group. From that and this, I think I've pieced together what you are trying to do: you want show a picture for 30 seconds and record if someone presses "k" during that time, but not advance to the next page.

So, you should have two questions on your page: (1) a Descriptive Text question that shows the picture and (2) An unforced Multiple Choice, Multiple Answer question with a single answer option that will record if "k" was pressed. If you have anything else (e.g. a timing question) delete it. Then add the following script to the multiple choice question. It will hide the buttons, hide the multiple choice question, hide the question separator, record if "k" is pressed (as the answer to the multiple choice question), and advance the page after 30 seconds.

Qualtrics.SurveyEngine.addOnload(function()
{
    setTimeout("$('NextButton').click()",30*1000);
    $('NextButton').hide();
    if($('PreviousButton')) $('PreviousButton').hide();
    $(this.questionId).hide();
    $$('.Separator').invoke('hide');
    var that = this;

    Event.observe(document, 'keydown', function keydownCallback(e) {
        if(e.keyCode == 75) {
            that.setChoiceValue(1,'true');
        }
    });
});
查看更多
登录 后发表回答