Self Paced Reading: Participants can currently hold down spacebar to reveal words!

I’m coding an experiment where participants read a sentence word-by-word at their own pace by pressing the spacebar. At some point in the sentence, a lexical decision task screen is presented which interrupts the flow of the self paced reading. Once participants have responded, another routine picks up where the previous self paced reading routine got to so they can reveal the rest of the sentence word-by-word. The self paced reading and lexical decision including the self paced reading routine that picks up after the lexical decision all work great. HOWEVER, participants are currently able to hold down the spacebar and fly through the entire sentence until the lexical decision screen is presented. I can’t work out how to code in that the spacebar cannot be pressed and held, and instead must be pressed and released in order for the next word of the sentence to be revealed.

My experimental loop looks like this:

The code that I have for the self paced reading component is as follows:

BEGIN ROUTINE:

psychoJS.eventManager.clearKeys()

words = Sentence.split(' ')
sentPos = 0
stimulusDisplay.text = words[sentPos]

EACH FRAME:

theseKeys = event.getKeys()

if (theseKeys == "space"){
    sentPos = sentPos + 1
    stimulusDisplay.text = words[sentPos]}
            
if (sentPos == words.length){
                continueRoutine = false}
            if (sentPos == probe_position_num){
                continueRoutine = false}

I’d really appreciate it if anybody had any good ideas on how to get this working as expected!

Thanks,

Paul