Keyboard keypresses are ignored

Hello experts,

I’m programming a psychology experiment using jsPsych and P5. Participants should see a stimulus on the screen, make a decision, press a button, and get feedback on the accuracy of their response before moving on to the next stimulus.

(here’s what I have so far - press F if the noise contains the letter E and G if it doesn’t).

The problem is, some keypresses are ignored for some reason. I think this mostly happens if you press the same key for two stimuli in a row, but it also happens on other occasions. I suspect this is not a problem with jsPsych because when I ask p5 to console.log the keycode after every keypress, these keypresses are not printed in the console.

Here’s the code for the above demo and here are the relevant lines from the p5 code and here is a minimal version that reproduces the issue without showing the stimuli (and the relevant lines).

I’ve been breaking my head on this all day, so any hint would be super useful.
Many thanks!!

Hello,

I only tried the debug code…

It is responsive with:
p.keyReleased

:)

Thanks glv! Any idea why this is the case? I’m asking because ideally I would like it to respond to the keypress, not the key release.
cheers!

It seems to work okay when I remove the p.remove from the p.keyPressed function. I guess p5 needs to record the key release in order to be able to record the next keypress, even if the next press is in a new p5 instance?

1 Like

Hell @tanzor,

I am not an expert but do like to find solutions to problems; the coding challenges here are one way to work the brain.

It was a fun exploration for me and I learned something along the way.

A deeper study of p5.js and JavaScript are on my to do list.

Thanks for sharing.

Have fun!

:)

1 Like

were able to get through this? Please share how you solved. I am making a tool similar to https://spacebarclicker.info and my spacebar presses are getting ignored for some reason. I have tried removing p.remove but it did not work. Please help!