p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

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

Open perminder-17 opened this issue 6 months ago • 1 comments

Most appropriate sub-area of p5.js?

  • [ ] Accessibility
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [x] 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.

https://github.com/processing/p5.js/blob/c39ad5c452d773a18de4c03067a7315422442eb4/src/events/keyboard.js#L463-L465

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

perminder-17 avatar Jun 05 '25 02:06 perminder-17

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

ksen0 avatar Jun 06 '25 08:06 ksen0

Linked PR has been closed

ksen0 avatar Sep 16 '25 13:09 ksen0