Solved
How to record which key is being pressed
Hi. I have added a key response ('j' and 'k'), and auto-advance features to my survey, despite they are working, the output doesn't seem to record which key is being pressed. Is there something that I missed adding into the javascript which makes it record which key is pressed?
This is the script that I used in my survey.
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 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();
}
});
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Best answer by TomG
The code you posted requires that you have a one multiple choice question on the page with two choices where the choice ids are 1 and 2. If that's the case, then if choice 1 is selected, they pressed j. If choice 2 is selected they pressed k.
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.