Skip to content

[p5.js 2.0 Bug Report]: KeyReleased() is not working in p5.js 2.0 #7759

@perminder-17

Description

@perminder-17

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

2.0

Web browser and version

firefox, chrome

Operating system

linux

Steps to reproduce this

Steps:

  1. Go to this link : https://editor.p5js.org/aman12345/sketches/g2-BEKriq
  2. Press any key
  3. See the error, you will see just an empty string " " on the console.

Snippet:

// Click on the canvas to begin detecting key presses.

let value = 0;

function setup() {
  createCanvas(100, 100);

  describe(
    'A gray square with a black square at its center. The inner square becomes white when the user releases the "w" key.'
  );
}

function draw() {
  background(200);

  // Style the square.
  fill(value);

  // Draw the square.
  square(25, 25, 50);
  // console.log(key)
}

// Set value to 255 the user releases the 'w' key.
function keyReleased() {
  if (key === 'w') {
    value = 255;
  } else{
    console.log(key);
  }
  // Uncomment to prevent any default behavior.
  // return false;
}

The expected behavior should be, when we press any key, the key must be shown on our console. The problem likely points to keyReleased().

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions