Skip to content

Commit 345f1aa

Browse files
authored
Merge pull request #7808 from AhmedMagedC/bug-fix-keyTyped
Fix: keyTyped() can now accept the same char consecutively
2 parents a990d4f + f7233a4 commit 345f1aa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/events/keyboard.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,13 @@ p5.prototype.keyCode = 0;
441441
* </div>
442442
*/
443443
p5.prototype._onkeydown = function(e) {
444+
// Ignore repeated key events when holding down a key
444445
if (e.repeat) {
445-
// Ignore repeated key events when holding down a key
446+
this._setProperty('isKeyRepeated', true);
446447
return;
447448
}
448449

450+
this._setProperty('isKeyRepeated', false);
449451
this._setProperty('isKeyPressed', true);
450452
this._setProperty('keyIsPressed', true);
451453
this._setProperty('keyCode', e.which);
@@ -781,7 +783,7 @@ p5.prototype._onkeyup = function(e) {
781783
* </div>
782784
*/
783785
p5.prototype._onkeypress = function(e) {
784-
if (e.which === this._lastKeyCodeTyped) {
786+
if (e.which === this._lastKeyCodeTyped && this.isKeyRepeated) {
785787
// prevent multiple firings
786788
return;
787789
}

0 commit comments

Comments
 (0)