Skip to content

Add FES warning for keyCode === usage to help transition from 1.x to 2.0 #7876

@amy-b

Description

@amy-b

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 keyCode is 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Open for Discussion

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions