Skip to content

[p5.js 2.0+ Bug Report]: key docs needs updating #9296

Open

Description

@eyaler

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • WebGPU
  • p5.strands
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2

Web browser and version

na

Operating system

na

Steps to reproduce this

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

Activity

  1. ksen0 commented on Oct 16, 2026

    @ksen0
    Member

    Thanks for spotting this!

    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:

    1. Remove the false statement "key doesn’t update for special keys such as LEFT_ARROW and ENTER"
    2. Note that key is updated to empty string when released as opposed to rettaining the last value in 1.x
    3. Great to have: update examples to use keyIsDown
    4. Also great to have would be a link to the code reference 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?

  2. eyaler commented on Oct 16, 2026

    @eyaler
    Author

    @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.

  3. ksen0 commented on Oct 16, 2026

    @ksen0
    Member

    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.

  4. MannXo commented on Oct 16, 2026

    @MannXo

    Interested in working on this. Can I be assigned?

  5. ksen0 commented on Oct 16, 2026

    @ksen0
    Member

    @MannXo please read the above comment, thank you!

  6. MYMISERABLEMIND17 commented on Oct 19, 2026

    @MYMISERABLEMIND17

    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:

    1. Clarify special key behavior: Remove the outdated claim that key doesn't update for special keys like LEFT_ARROW and ENTER.
    2. 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).
    3. 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.
    4. 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?

  7. lipe-manza commented on Nov 11, 2026

    @lipe-manza

    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?

    Thanks!

  8. ksen0 commented on Nov 11, 2026

    @ksen0
    Member

    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.

  9. lipe-manza commented on Nov 12, 2026

    @lipe-manza

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions