# Keyboard keypresses are ignored

**URL:** <https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781>\
**Category:** Libraries\
**Created:** [January 21, 2022, 8:08pm UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781 "2022-01-21T20:08:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanzor](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@tanzor](https://discourse.processing.org/u/tanzor)\
**Post date:** [January 21, 2022, 8:08pm UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781/1 "2022-01-21T20:08:13Z")

</div>

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](https://matanmazor.github.io/detectionInContext/experiments/pilots/letters/index) - 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](https://github.com/matanmazor/detectionInContext/tree/main/experiments/pilots/letters) and here are [the relevant lines from the p5 code](https://github.com/matanmazor/detectionInContext/blob/7a36484dd7f1786f6b16eeff678291abc1cc6c4a/experiments/pilots/letters/jspsych/plugin-noisy-letter.js#L125) and here is [a minimal version that reproduces the issue without showing the stimuli](https://github.com/matanmazor/detectionInContext/tree/main/experiments/pilots/debug) (and [the relevant lines](https://github.com/matanmazor/detectionInContext/blob/7a36484dd7f1786f6b16eeff678291abc1cc6c4a/experiments/pilots/debug/jspsych/plugin-noisy-letter.js#L42)).

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 22, 2022, 8:22pm UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781/2 "2022-01-22T20:22:57Z")

</div>

Hello,

I only tried the _debug_ code…

It is responsive with:  
`p.keyReleased`

`:)`

---

<div class="post-metadata">

**Author:** ![tanzor](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@tanzor](https://discourse.processing.org/u/tanzor)\
**Post date:** [January 22, 2022, 9:03pm UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781/3 "2022-01-22T21:03:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![tanzor](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@tanzor](https://discourse.processing.org/u/tanzor)\
**Post date:** [January 22, 2022, 11:46pm UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781/4 "2022-01-22T23:46:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 23, 2022, 10:45am UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781/5 "2022-01-23T10:45:40Z")

</div>

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!

`:)`

---

<div class="post-metadata">

**Author:** ![alexcarson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/alexcarson/32/16291_2.png) [@alexcarson](https://discourse.processing.org/u/alexcarson)\
**Post date:** [May 24, 2022, 7:10am UTC](https://discourse.processing.org/t/keyboard-keypresses-are-ignored/34781/6 "2022-05-24T07:10:05Z")

</div>

were able to get through this? Please share how you solved. I am making a tool similar to [https://spacebarclicker.info](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!
