Hi Marton,
Thanks for alerting me about the possibility. I (somehow) hadn't thought about that and the RDK initially could only take in responses from character keys. I've added functionality to the RDK so now it is able to take in
JavaScript Key Codes too. I've tested it and you should be able to use arrows now (key codes 37-40). :)
A snippet of the updated code is below. Unfortunately I can't seem to send a .js file through email and somehow couldn't change the filename. Instead, you can just replace the entire
correctOrNot function (line
585 in
jspsych-RDK.js, in the
plugins folder) with the code below, and it should work.
Hope that helps!
------------------------------------------------------------------------------------------
//Function that determines if the response is correct
function correctOrNot(){
//Check that the correct_choice has been defined
if(typeof trial.correct_choice !== 'undefined'){
//If the correct_choice variable holds an array
if(trial.correct_choice.constructor === Array){ //If it is an array
//If the elements are characters
if(typeof trial.correct_choice[0] === 'string' || trial.correct_choice[0] instanceof String){
trial.correct_choice = trial.correct_choice.map(function(x){return x.toUpperCase();}); //Convert all the values to upper case
return trial.correct_choice.includes(String.fromCharCode(response.key)); //If the response is included in the correct_choice array, return true. Else, return false.
}
//Else if the elements are numbers (javascript character codes)
else if (typeof trial.correct_choice[0] === 'number'){
return trial.correct_choice.includes(response.key); //If the response is included in the correct_choice array, return true. Else, return false.
}
}
//Else compare the char with the response key
else{
//If the element is a character
if(typeof trial.correct_choice === 'string' || trial.correct_choice instanceof String){
//Return true if the user's response matches the correct answer. Return false otherwise.
return response.key == trial.correct_choice.toUpperCase().charCodeAt(0);
}
//Else if the element is a number (javascript character codes)
else if (typeof trial.correct_choice === 'number'){
console.log(response.key == trial.correct_choice);
return response.key == trial.correct_choice;
}
}
}
}
------------------------------------------------------------------------------------------