@@ -15,7 +15,7 @@ define(function (require) {
1515 * @property _downKeys
1616 * @private
1717 */
18- p5 . prototype . _downKeys = [ ] ;
18+ p5 . prototype . _downKeys = { } ;
1919
2020 /**
2121 * The boolean system variable keyIsPressed is true if any key is pressed
@@ -120,9 +120,7 @@ define(function (require) {
120120 this . _setProperty ( 'isKeyPressed' , true ) ;
121121 this . _setProperty ( 'keyIsPressed' , true ) ;
122122 this . _setProperty ( 'keyCode' , e . which ) ;
123- if ( this . _downKeys . indexOf ( e . which ) < 0 ) {
124- this . _downKeys . push ( e . which ) ;
125- }
123+ this . _downKeys [ e . which ] = true ;
126124 var key = String . fromCharCode ( e . which ) ;
127125 if ( ! key ) {
128126 key = e . which ;
@@ -167,9 +165,8 @@ define(function (require) {
167165 var keyReleased = this . keyReleased || window . keyReleased ;
168166 this . _setProperty ( 'isKeyPressed' , false ) ;
169167 this . _setProperty ( 'keyIsPressed' , false ) ;
170- if ( this . _downKeys . indexOf ( e . which ) >= 0 ) {
171- this . _downKeys . splice ( this . _downKeys . indexOf ( e . which ) , 1 ) ;
172- }
168+ this . _downKeys [ e . which ] = false ;
169+ //delete this._downKeys[e.which];
173170 var key = String . fromCharCode ( e . which ) ;
174171 if ( ! key ) {
175172 key = e . which ;
@@ -267,7 +264,7 @@ define(function (require) {
267264 * </div>
268265 */
269266 p5 . prototype . keyIsDown = function ( code ) {
270- return this . _downKeys . indexOf ( code ) >= 0 ;
267+ return this . _downKeys [ code ] ;
271268 } ;
272269
273270 return p5 ;
0 commit comments