You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs for key read: "key doesn’t update for special keys such as LEFT_ARROW and ENTER. Use keyCode instead for special keys". however key now works with LEFT_ARROW and keyCode is deprecated
Currently, we recommend keyIsDown in general, instead of ===, now. This pattern is backwards compatible now, and can be more robust to changes in the future.
So the PR on p5.js repo addressing this should ideally:
Remove the false statement "key doesn’t update for special keys such as LEFT_ARROW and ENTER"
Note that key is updated to empty string when released as opposed to rettaining the last value in 1.x
Please do not duplicate the details of the code page, but it does contains an overview of changes from 1.x to 2.x regarding key, code, and keyCode that may be helpful to anyone trying to figure out the differences.
The latest 1.x API reference is live on v1.p5js.org, if context is helpful; as context, here is a list of all changes between 1.x and 2.x.
@eyaler are you interested in working on this or should I mark it as available for volunteer work?
Thanks for the quick response. Ive added the additional point to the list and will open this for contribution.
I'll mark this one as a good first issue. Note to volunteers who want to work on it: please to carefully review our guidelines, including AI usage policy; please do not file PRs without being assigned first. Consistently not following guidelines may result in temporary account suspension; if you're here because you want to apply for GSoC, not following guidelines will likely result in rejection. Thanks in advance for undertanding.
Hi @ksen0, I've reviewed the issue description, the discussion points above, and the contributor guidelines/AI policy.
I inspected src/events/keyboard.js (lines 110–182) and verified the behavior against the 2.x event lifecycle (e.g. keyup handler resetting this.key = '' when no keys remain pressed, and keydown capturing all key values including special keys like 'ArrowLeft' and 'Enter').
Here is what I've prepared to address the 4 points:
Clarify special key behavior: Remove the outdated claim that key doesn't update for special keys like LEFT_ARROW and ENTER.
Document key release lifecycle: Note that in 2.x, key resets to an empty string "" once all keys are released (unlike 1.x which retained the last pressed value).
Recommend keyIsDown: State that keyIsDown() is recommended over key === ... for continuous polling in draw(), and update Example 2 to demonstrate keyIsDown('w'), keyIsDown('s'), etc.
Link to code reference: Include a reference link to the code reference page (https://p5js.org/reference/p5/code/) for the complete 1.x vs 2.x overview of key, code, and keyCode.
I have verified the changes locally against npx vitest run test/unit/events/keyboard.js, oxlint, and npm run docs. Could you please assign this issue to me so I can open the pull request?
Hi @eyaler! I'm a Computer Science student at the University of São Paulo (USP), Brazil. I'm currently taking an Open Source Software course, where one of our assignments is to contribute to an open-source project by working on an issue and submitting a pull request.
I'd like to work on this issue and be assigned to it if it's still available.
After reading the discussion and looking into src/events/keyboard.js, here's what I understood:
The current documentation is outdated because key is not limited to ASCII characters. It also handles special keys such as Enter and ArrowDown, using the browser's KeyboardEvent.key value.
In p5.js 2.x, key generally represents the most recently pressed key that is still being held down. If that key is released while another remains pressed, key is updated to reflect a remaining key. When all keys are released, it resets to an empty string (''), unlike in p5.js 1.x, where it retained the last key value.
Since key stores only one value at a time, keyIsDown() is more appropriate for checking whether specific keys are being held down, especially when multiple keys are pressed simultaneously.
My plan is to update the JSDoc documentation for key, remove the outdated statements, explain the behavior when keys are released, update the examples to use keyIsDown(), and add a link to the code reference page.
I'll keep the changes focused on documentation and validate them locally before submitting a PR.
I've also read the contribution guidelines to understand more how it works!
Would it be possible to assign this issue to me if it's still available?
@MYMISERABLEMIND17 sorry for not assigning in order; This is based on reviewing your comments on multiple issues looking for assignment, which do appear, as a whole to be using LLMs in a way that make it very difficult to determine how much of the issue you have understood. You can read more detailed comments about what is expected, instead of a very direct restatement, here, I hope that helps.
Hi @ksen0 ! Thanks for the go-ahead! I've opened PR #9398 addressing this issue. I noticed I'm not formally assigned yet. Would you mind assigning me? Thanks!
Activity
ksen0 commentedon Oct 16, 2026
Thanks for spotting this!
Currently, we recommend
keyIsDownin general, instead of===, now. This pattern is backwards compatible now, and can be more robust to changes in the future.So the PR on
p5.jsrepo addressing this should ideally:keyIsDowncodereference page: link to https://p5js.org/reference/p5/code/Please do not duplicate the details of the code page, but it does contains an overview of changes from 1.x to 2.x regarding key, code, and keyCode that may be helpful to anyone trying to figure out the differences.
The latest 1.x API reference is live on v1.p5js.org, if context is helpful; as context, here is a list of all changes between 1.x and 2.x.
@eyaler are you interested in working on this or should I mark it as available for volunteer work?
eyaler commentedon Oct 16, 2026
@ksen0 also:
4. key is updated to empty string when released as opposed to rettaining the last value in 1.x
unfortunately i am not currently available to do this.
ksen0 commentedon Oct 16, 2026
Thanks for the quick response. Ive added the additional point to the list and will open this for contribution.
I'll mark this one as a good first issue. Note to volunteers who want to work on it: please to carefully review our guidelines, including AI usage policy; please do not file PRs without being assigned first. Consistently not following guidelines may result in temporary account suspension; if you're here because you want to apply for GSoC, not following guidelines will likely result in rejection. Thanks in advance for undertanding.
MannXo commentedon Oct 16, 2026
Interested in working on this. Can I be assigned?
ksen0 commentedon Oct 16, 2026
@MannXo please read the above comment, thank you!
MYMISERABLEMIND17 commentedon Oct 19, 2026
Hi @ksen0, I've reviewed the issue description, the discussion points above, and the contributor guidelines/AI policy.
I inspected
src/events/keyboard.js(lines 110–182) and verified the behavior against the 2.x event lifecycle (e.g.keyuphandler resettingthis.key = ''when no keys remain pressed, andkeydowncapturing all key values including special keys like'ArrowLeft'and'Enter').Here is what I've prepared to address the 4 points:
keydoesn't update for special keys likeLEFT_ARROWandENTER.keyresets to an empty string""once all keys are released (unlike 1.x which retained the last pressed value).keyIsDown: State thatkeyIsDown()is recommended overkey === ...for continuous polling indraw(), and update Example 2 to demonstratekeyIsDown('w'),keyIsDown('s'), etc.codereference: Include a reference link to thecodereference page (https://p5js.org/reference/p5/code/) for the complete 1.x vs 2.x overview ofkey,code, andkeyCode.I have verified the changes locally against
npx vitest run test/unit/events/keyboard.js,oxlint, andnpm run docs. Could you please assign this issue to me so I can open the pull request?lipe-manza commentedon Nov 11, 2026
Hi @eyaler! I'm a Computer Science student at the University of São Paulo (USP), Brazil. I'm currently taking an Open Source Software course, where one of our assignments is to contribute to an open-source project by working on an issue and submitting a pull request.
I'd like to work on this issue and be assigned to it if it's still available.
After reading the discussion and looking into
src/events/keyboard.js, here's what I understood:keyis not limited to ASCII characters. It also handles special keys such asEnterandArrowDown, using the browser'sKeyboardEvent.keyvalue.keygenerally represents the most recently pressed key that is still being held down. If that key is released while another remains pressed,keyis updated to reflect a remaining key. When all keys are released, it resets to an empty string (''), unlike in p5.js 1.x, where it retained the last key value.keystores only one value at a time,keyIsDown()is more appropriate for checking whether specific keys are being held down, especially when multiple keys are pressed simultaneously.My plan is to update the JSDoc documentation for
key, remove the outdated statements, explain the behavior when keys are released, update the examples to usekeyIsDown(), and add a link to thecodereference page.I'll keep the changes focused on documentation and validate them locally before submitting a PR.
I've also read the contribution guidelines to understand more how it works!
Would it be possible to assign this issue to me if it's still available?
Thanks!
ksen0 commentedon Nov 11, 2026
Hi @lipe-manza , thanks, go ahead! This will be useful for locally testing the reference: https://p5js.org/contribute/contributing_to_the_p5js_reference/ if it gets tricky you can ask for help here or on discord.p5js.org in #contribute-to-p5
@MYMISERABLEMIND17 sorry for not assigning in order; This is based on reviewing your comments on multiple issues looking for assignment, which do appear, as a whole to be using LLMs in a way that make it very difficult to determine how much of the issue you have understood. You can read more detailed comments about what is expected, instead of a very direct restatement, here, I hope that helps.
lipe-manza commentedon Nov 12, 2026
Hi @ksen0 ! Thanks for the go-ahead! I've opened PR #9398 addressing this issue. I noticed I'm not formally assigned yet. Would you mind assigning me? Thanks!