@@ -441,15 +441,25 @@ p5.prototype.keyCode = 0;
441
441
* </div>
442
442
*/
443
443
p5 . prototype . _onkeydown = function ( e ) {
444
- if ( this . _downKeys [ e . which ] ) {
445
- // prevent multiple firings
444
+ if ( e . repeat ) {
445
+ // Ignore repeated key events when holding down a key
446
446
return ;
447
447
}
448
+
448
449
this . _setProperty ( 'isKeyPressed' , true ) ;
449
450
this . _setProperty ( 'keyIsPressed' , true ) ;
450
451
this . _setProperty ( 'keyCode' , e . which ) ;
451
452
this . _downKeys [ e . which ] = true ;
452
453
this . _setProperty ( 'key' , e . key || String . fromCharCode ( e . which ) || e . which ) ;
454
+
455
+ // Track keys pressed with meta key
456
+ if ( e . metaKey ) {
457
+ if ( ! this . _metaKeys ) {
458
+ this . _metaKeys = [ ] ;
459
+ }
460
+ this . _metaKeys . push ( e . which ) ;
461
+ }
462
+
453
463
const context = this . _isGlobal ? window : this ;
454
464
if ( typeof context . keyPressed === 'function' && ! e . charCode ) {
455
465
const executeDefault = context . keyPressed ( e ) ;
@@ -458,6 +468,7 @@ p5.prototype._onkeydown = function(e) {
458
468
}
459
469
}
460
470
} ;
471
+
461
472
/**
462
473
* A function that's called once when any key is released.
463
474
*
@@ -615,18 +626,21 @@ p5.prototype._onkeydown = function(e) {
615
626
* </div>
616
627
*/
617
628
p5 . prototype . _onkeyup = function ( e ) {
629
+ this . _setProperty ( 'isKeyPressed' , false ) ;
630
+ this . _setProperty ( 'keyIsPressed' , false ) ;
631
+ this . _setProperty ( '_lastKeyCodePressed' , this . _keyCode ) ;
618
632
this . _downKeys [ e . which ] = false ;
619
633
620
- if ( ! this . _areDownKeys ( ) ) {
621
- this . _setProperty ( 'isKeyPressed' , false ) ;
622
- this . _setProperty ( 'keyIsPressed' , false ) ;
634
+ if ( e . key === 'Meta' ) { // Meta key codes
635
+ // When meta key is released, clear all keys pressed with it
636
+ if ( this . _metaKeys ) {
637
+ this . _metaKeys . forEach ( key => {
638
+ this . _downKeys [ key ] = false ;
639
+ } ) ;
640
+ this . _metaKeys = [ ] ;
641
+ }
623
642
}
624
643
625
- this . _setProperty ( '_lastKeyCodeTyped' , null ) ;
626
-
627
- this . _setProperty ( 'key' , e . key || String . fromCharCode ( e . which ) || e . which ) ;
628
- this . _setProperty ( 'keyCode' , e . which ) ;
629
-
630
644
const context = this . _isGlobal ? window : this ;
631
645
if ( typeof context . keyReleased === 'function' ) {
632
646
const executeDefault = context . keyReleased ( e ) ;
0 commit comments