getting RDK plugin to accept numpad/arrow key for correct_choice

58 views
Skip to first unread message

Marton Kocsis

unread,
Sep 5, 2018, 3:03:45 AM9/5/18
to jsp...@googlegroups.com
I am trying to build a 4-directional RDK task where the correct responses map onto either the arrow keys or numpad arrow keys. 

Seeing as correct_choice will only accept character names while response converts arrow/numpad keys to character codes, what is the best way to use the arrow/numpad keys as correct_choices?
RDK_tut.html

Josh de Leeuw

unread,
Sep 7, 2018, 10:08:41 AM9/7/18
to Marton Kocsis, jsp...@googlegroups.com, Sivananda R
Looping in Siva (RDK developer) to this conversation to see if he can answer the question.

On Wed, Sep 5, 2018 at 3:03 AM Marton Kocsis <marton...@research.uwa.edu.au> wrote:
I am trying to build a 4-directional RDK task where the correct responses map onto either the arrow keys or numpad arrow keys. 

Seeing as correct_choice will only accept character names while response converts arrow/numpad keys to character codes, what is the best way to use the arrow/numpad keys as correct_choices?

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/CAOXpG2WZ%2BOX8_cxRc3zsMAJyQCfxmMdD9QCkF3CFY5G7f1C8vQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Sivananda Rajananda

unread,
Sep 7, 2018, 8:27:40 PM9/7/18
to Josh de Leeuw, marton...@research.uwa.edu.au, jsp...@googlegroups.com, Brian Odegaard
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!

-Siva

PS. Josh, thanks for looping me in. I've created a pull request so that you can merge it into your main JsPsych library whenever you are free (I've updated the docs to reflect the change too).

PPS. Looping Brian in as he supervised the development of the RDK.

Code to replace:
------------------------------------------------------------------------------------------

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

------------------------------------------------------------------------------------------

Marton Kocsis

unread,
Sep 12, 2018, 9:48:55 PM9/12/18
to jsp...@googlegroups.com
I am using the RDK as a distractor task presented between individual stimuli during list presentation, but after first RDK trial finishes the background color for the rest of trial elements (a number of html+keyboard responses and one html sliding response) is set to grey (presumably on the basis of the default background color from RDK task). 

Is there a way I can avoid the background color for the RDK overwriting the background color for subsequent trial elements?

All the best,
Marton
Reply all
Reply to author
Forward
0 new messages