Add FES warning for keyCode === usage to help transition from 1.x to 2.0
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Increasing access
This feature would increase access by making it easier for learners and users transitioning from p5.js 1.x to 2.0 to identify and fix breaking changes.
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)
Feature enhancement details
in p5.js 2.0, there was an important change to how key and code are handled to align better with the widely used web standards spec reference.
Previously, it was common in 1.x to compare keyCode directly to constants like RIGHT_ARROW and LEFT_ARROW.
if (keyCode === RIGHT_ARROW) {
background(0);
} else if (keyCode === LEFT_ARROW) {
background(100);
}
Though this works in 1.x, it no longer works in 2.0 due to the standardization update. Now, users must use:
if (keyIsDown(RIGHT_ARROW)) {
background(0);
} else if (keyIsDown(LEFT_ARROW)) {
background(100);
}
Problem: Many 1.x users are accustomed to using keyCode === without needing to reference documentation. Since this behavior no longer works in 2.0, it can be confusing and lead to subtle bugs when transitioning projects. This can be particularly frustrating for those who rely on prior p5.js experience.
Currently there is no warning given when keyCode === is used, which can be harder to debug.
Proposed Solution: Add a Friendly Error System warning that:
- Detects patterns where
keyCodeis compared using===or== - Shows a warning suggestion to use
keyIsDown()instead - (Maybe) link to the updated documentation for
keyIsDown()
Possible warning message: keyCode === is deprecated in p5.js 2.0. Please use keyIsDown instead. See https://beta.p5js.org/reference/p5/keyisdown/ for more information.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing p5.js's Friendly Error System and its existing warning behavior for event-related code. Determine how it can detect keyCode comparisons using === or ==, then verify that the warning recommends keyIsDown() and links to the updated reference documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100