psychopy.org | Reference | Downloads | Github

Force keypress release

I am creating a self-paced reading task to be run online. Participants see one word at the time on their screen and press spacebar to replace the current word by the next word of the sentence.

If I run the study offline using PsychoPy, participants are not able to rush through the experiment by keeping the spacebar pressed. One needs to release the spacebar and press it again to continue to the third word. But if I keep the spacebar pressed while running the task on Pavlovia, the replacement of the words will continue.

This is my JS code:

// Begin routine
sentenceList = sentence.split(" ");
wordNumber = -1;
timeofLastResponse = 0;
word_text.text = '#';

// Each frame
let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) {  
 if (theseKeys.includes('space')){
     thisResponseTime = t;
     wordNumber++;
     if (wordNumber < sentenceList.length) {
         psychoJS.experiment.addData("word" + (wordNumber+1), thisResponseTime - timeofLastResponse);
         timeofLastResponse = thisResponseTime;
         word_text.text = sentenceList[wordNumber];
     }
     else {
         continueRoutine = false;}
 } else if (theseKeys.includes('esc')){
     core.quit();}} 

I tried clearKeys(), but this didn’t change anything. I then tried to solve this issue by using the Keyboard class with the waitRelease function.

// Begin routine
...
keyboard = new core.Keyboard({PsychoJS});

// Each frame
let theseKeys = keyboard.getKeys(waitRelease = true);
...

Unfortunately, this doesn’t work: the experiment will not proceed to the first word of the sentence and stays on # (the first screen).

Is there a way to prevent participants from keeping the spacebar pressed?