processing/p5.js

key may be incorrect inside an event handler

Open

#7,569 opened on Feb 20, 2025

View on GitHub
 (9 comments) (0 reactions) (0 assignees)JavaScript (20,784 stars) (3,178 forks)batch import
Area:EventsBugHelp Wanted

Description

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

1.11.3

Web browser and version

Firefox 135.0 / Chromium 133

Operating system

Linux 6.13.2

Steps to reproduce this

Steps:

  1. Press key d
  2. Press and then release key a
  3. Release key d. In keyReleased key will be equal to a, though ev.key will be correct (d).

This happens since 1.11.3. In 1.11.2 and before everything works correctly.

There's also an issue with keyPressed in Firefox (not in Chromium). It fires continuously while a key is pressed, not just once. It is probably linked to this issue, since it started happening in 1.11.3, I don't know if I should create a new issue about that too.

Snippet:

function keyPressed(ev) {
	console.log(`pressed ${ev.key} (p5.key = ${key})`);
}

function keyReleased(ev) {
	console.log(`released ${ev.key} (p5.key = ${key})`);
}

Contributor guide

key may be incorrect inside an event handler · processing/p5.js#7569 | Good First Issue