p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

keyTyped does not work in conjunction with returning false in mousePressed

Open BenMaydan opened this issue 5 years ago • 7 comments

Most appropriate sub-area of p5.js?

  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] Events
  • [ ] Image
  • [x] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Details about the bug:

  • p5.js version:
  • Web browser and version: Chrome, version "80.0.3987.132"
  • Operating System: Windows 10 OS Version 1909
  • Steps to reproduce this: return false in mousePressed, and suddenly you can't access anything to do with the keyboard

print(key) does not print anything. Code is below

function setup() { createCanvas(400, 400); }

function draw() { background(220); }

function mousePressed() { return false; }

function keyPressed() { print(key); }

BenMaydan avatar Mar 14 '20 07:03 BenMaydan

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

welcome[bot] avatar Mar 14 '20 07:03 welcome[bot]

I would like to work on this. Seems like an issue with an EventListener.

pcgamer1 avatar Mar 14 '20 14:03 pcgamer1

@BenMaydan I'm not able to replicate this locally, can this be a web editor bug?

limzykenneth avatar Mar 14 '20 15:03 limzykenneth

with return false it triggers e.preventDefault(). my guess is that after the click, the iframe in web editor does not capture the cursor even if you click, and thus doesn't catch key events. If you click on the editor console and hit tab a few times to select iframe, key events are fired properly

micuat avatar Jun 06 '20 15:06 micuat

sounds right, @micuat see the same https://editor.p5js.org/kll/sketches/tLtOxsq78 here.

kllsamui avatar Jul 30 '20 12:07 kllsamui

I'd like to point out as of April 2022 I fould the same problem as OP, when I call return false on mousePressed() it breaks the code in keyPressed()

Dainess avatar Apr 26 '22 10:04 Dainess

This issue only happens in the web editor, please file this bug over here instead. Thanks.

limzykenneth avatar Aug 14 '22 10:08 limzykenneth