psychopy.org | Reference | Downloads | Github

Checking for keyboard response using code component online

URL of experiment: https://gitlab.pavlovia.org/Felicia/sliderexp

Description of the problem:

Hey there,

I am using a slider element in an online experiment. At first, I let them continue to the next question using a keyboard component (so pressing SPACE would end the routine). But like this they could jump to the next question without choosing a rating on the slider which lead to missing answers. So I exchanged the keyboard component for a code component where I check for a rating first before checking for a keyboard response. Locally this works absolutely fine, but online it doesn’t work. Now I can’t jump to the next question without choosing a rating, but even after choosing a rating, the routine will not end when pressing SPACE.

Does anyone know how to solve this? I guess there is something wrong with the js syntax. I tried to do it like in the auto-generated js file from the previous version where I used a keyboard component to end the routine. This is the js part of my code component:

key_response = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});
let theseKeys = key_response.getKeys({keyList: ['space'], waitRelease: false});

if ((slider.getRating() !== null)) {
    valid_response = true;
}
if (valid_response) {
    if (theseKeys.length > 0) {
        if ((theseKeys[0] === "space")) {
            continueRoutine = false;
        }
    }
}

this is the PsychoPy-Version which works locally:

key_response = keyboard.Keyboard()
theseKeys = key_response.getKeys(keyList=['space'], waitRelease=False)

if slider.getRating() != None:
    valid_response = True

if valid_response:
    if len(theseKeys):
        if theseKeys[0] == "space":
            continueRoutine = False
1 Like

Switch the code type to Both and change null to undefined

Best wishes

Wakefield

Hey Wakefield,

thanks again for your help! I tried it with undefined, but unfortunately it still does not work. Do you have any other idea what I could do?

I haven’t managed to get the new keyboard class working online. Try event.getKeys() with event defined in code_JS as per my crib sheet

That worked :slight_smile:

Thank you so much!