-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add FES warning for keyCode === usage to help transition from 1.x to 2.0 #7876
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
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you! |
Thanks for finding this @amy-b ! Thinking along with the proposed solutions: in this example, multiple usages should still only cause a single warning. The example here is not an error on 2.0, it just doesn't behave as expected. There definitely can be intentional uses of @perminder-17 Do you think the reference should list LEFT_ARROW and other constants more explicitly somewhere? Seems too noisy to list in the "Constants" section but maybe in key? The keyCode section links to keycode.info but key() seems to be missing a list (e.g., "The system variables BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, and RIGHT_ARROW are all helpful shorthands for the special keys.") |
Hi @amy-b, Thank you so much for bringing up this concern. You’re absolutely right, without a clear, friendly error message, users may be puzzled by the changes to I apologize for having overlooked documenting Lines 463 to 465 in c39ad5c
In the source (see keyboard.js), we can now compare constants like this: if (code === RIGHT_ARROW) {
// operations...
} I will promptly add documentation for Perhaps something along the lines of: Also, @ksen0, I believe the most appropriate location for this information is in the sections where |
Thank you so much @amy-b for pointing this out and I agree it's worth addressing this issue. Also, thanks to @ksen0 and @perminder-17 for the discussions so far on this. From the Friendly Errors perspective, I think this is a great opportunity to improve clarity for learners transitioning from p5.js I agree with @Kseno, As noted,
This wouldn’t throw an error or block execution, but would gently alert users that they're using an outdated pattern — helping them shift their mental model with minimal frustration. No doubt, type checks on either side of |
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?
Feature enhancement details
in p5.js 2.0, there was an important change to how
key
andcode
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 likeRIGHT_ARROW
andLEFT_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:
keyCode
is compared using===
or==
keyIsDown()
insteadkeyIsDown()
Possible warning message:
keyCode ===
is deprecated in p5.js 2.0. Please usekeyIsDown
instead. See https://beta.p5js.org/reference/p5/keyisdown/ for more information.The text was updated successfully, but these errors were encountered: