Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 17 tasks
perminder-17 opened this issue Jun 5, 2025 · 1 comment
Open
1 of 17 tasks

Comments

@perminder-17
Copy link
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.

@ksen0
Copy link
Member

ksen0 commented Jun 6, 2025

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

@ksen0 ksen0 added this to the 2.x Anytime milestone Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Work
Status: Ready for Work
Development

No branches or pull requests

2 participants