Skip to content

[p5.js 2.0 Bug Report]: Add documentation for the code system variable in key handling. #7881

@perminder-17

Description

@perminder-17
Collaborator

Most appropriate sub-area of p5.js?

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

p5.js version

2.x

Web browser and version

Firefox

Operating system

Linux

Steps to reproduce this

In p5.js, we currently support some ways to detect which key a user presses: keyCode, key, and code are some of it. While keyCode and key are documented in the reference, the code variable has not yet been documented, which can lead to confusion for users.

this.keyCode = e.which;
this.key = e.key;
this.code = e.code;

  • key returns the character or value associated with the key press, regardless of the keyboard layout.

  • code returns the Constants on the keyboard (e.g., ENTER, ArrowUP), independent of what character is printed on that key.

Because only key is documented, users do not know that code exists or how it behaves.

Activity

self-assigned this
on Jun 5, 2025
added theissue type on Jun 5, 2025
moved this to Ready for Work in p5.js 2.x 🌱🌳on Jun 5, 2025
moved this to Ready for Work in p5.js Documentationon Jun 5, 2025
ksen0

ksen0 commented on Jun 6, 2025

@ksen0
Member

For anyone who wants a bit more background on this, here is the issue where this 2.0 update was discussed

modified the milestones: 2.x Anytime, 2.1 on Jun 7, 2025
linked a pull request that will close this issue on Jun 11, 2025
linked a pull request that will close this issueAdding docs for `code` in the refrence. #7902on Jun 11, 2025
moved this from Ready for Work to In Progress in p5.js 2.x 🌱🌳on Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

Status

Ready for Work

Status

In Progress

Relationships

None yet

    Development

    Participants

    @ksen0@perminder-17

    Issue actions

      [p5.js 2.0 Bug Report]: Add documentation for the `code` system variable in key handling. · Issue #7881 · processing/p5.js