[p5.js 2.0 Bug Report]: [p5.js 2.0 Bug Report]: _onblur doesn't fully reset keyboard state , keyIsPressed and keyIsDown() stay stuck after losing focus
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript
Research direction
Start in keyboard.js at the _onblur handler and trace the state used by keyIsPressed and keyIsDown(). Reproduce the Alt-Tab scenario with the provided sketch, then verify that losing focus no longer leaves keyboard state stuck and that the relevant keyboard behavior remains correct.
Written by the indexing model from the issue text.
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
2.x (main)
Web browser and version
Any
Operating system
Windows 11, but doesn't matter
Steps to reproduce this
Steps:
- Open a sketch with keyboard input (see snippet below)
- Click the canvas, then hold down the right arrow key
- While still holding it, Alt-Tab to another window
- Release the key in the other window
- Switch back to the sketch tab
Snippet:
function setup() {
createCanvas(400, 200);
}
function draw() {
background(220);
textSize(16);
text('keyIsPressed: ' + keyIsPressed, 20, 40);
text('RIGHT_ARROW down: ' + keyIsDown(RIGHT_ARROW), 20, 80);
}
After step 5, both keyIsPressed and keyIsDown(RIGHT_ARROW) are still true even though no key is being held. The key stays "stuck" until you physically press and release it again inside the sketch. Super annoying in any movement-based sketch
Root cause:
_onblur in keyboard.js only clears _downKeys but completely ignores _downKeyCodes, keyIsPressed, key, and code:
// what's there now
fn._onblur = function(e) {
this._downKeys = {};
};
_downKeyCodes is new to 2.x _onblur was just never updated when it got added. Since keyIsDown() checks both maps, clearing only one of them doesn't actually fix the stuck state.,
Fix would be:
fn._onblur = function(e) {
this._downKeys = {};
this._downKeyCodes = {};
this.keyIsPressed = false;
this.key = '';
this.code = '';
};
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 26
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from processing/p5.js
-
Area:Math p5.js 2.0+
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
processing/p5.js#9197 · 3 comments · 1 assignee ·
-
Area:Core Area:DOM
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
processing/p5.js#9189 ·
-
[Bug]: p5.Image.prototype.copy and blend do not scale destination coordinates for high pixel density Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
processing/p5.js#9169 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
processing/p5.js#9129 ·
-
[p5.js 2.0+ Bug Report]: splitTokens() returns [] for a caret delimiter and throws for a backslash Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
processing/p5.js#9126 · 1 comment ·
All issues in processing/p5.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·