Skip to content

Commit 4f072e1

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents 0518a38 + 4e697be commit 4f072e1

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/addons/p5.sound.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ sndcore = function () {
9797
if (typeof AudioContext.prototype.createDelay !== 'function')
9898
AudioContext.prototype.createDelay = AudioContext.prototype.createDelayNode;
9999
if (typeof AudioContext.prototype.createScriptProcessor !== 'function')
100-
AudioContext.prototype.createScriptProcessor = AudioContext.prototype.createJavaScriptNode;
100+
AudioContext.prototype.createScriptProcessor = AudioContext.prototype.createScriptProcessor;
101101
if (typeof AudioContext.prototype.createPeriodicWave !== 'function')
102102
AudioContext.prototype.createPeriodicWave = AudioContext.prototype.createWaveTable;
103103
AudioContext.prototype.internal_createGain = AudioContext.prototype.createGain;
@@ -9334,4 +9334,4 @@ src_app = function () {
93349334
var p5SOUND = sndcore;
93359335
return p5SOUND;
93369336
}(sndcore, master, helpers, errorHandler, panner, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, delay, reverb, metro, looper, soundRecorder, peakdetect, gain, distortion);
9337-
}));
9337+
}));

src/events/keyboard.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,16 @@ p5.prototype._onkeydown = function (e) {
225225
*/
226226
p5.prototype._onkeyup = function (e) {
227227
var keyReleased = this.keyReleased || window.keyReleased;
228-
this._setProperty('isKeyPressed', false);
229-
this._setProperty('keyIsPressed', false);
230-
this._setProperty('_lastKeyCodeTyped', null);
231228
downKeys[e.which] = false;
232229
//delete this._downKeys[e.which];
233230
var key = String.fromCharCode(e.which);
231+
232+
if(areDownKeys()) {
233+
this._setProperty('isKeyPressed', false);
234+
this._setProperty('keyIsPressed', false);
235+
}
236+
237+
this._setProperty('_lastKeyCodeTyped', null);
234238
if (!key) {
235239
key = e.which;
236240
}
@@ -354,4 +358,22 @@ p5.prototype.keyIsDown = function(code) {
354358
return downKeys[code];
355359
};
356360

361+
/**
362+
* The checkDownKeys function returns a boolean true if any keys pressed
363+
* and a false if no keys are currently pressed.
364+
365+
* Helps avoid instances where a multiple keys are pressed simultaneously and
366+
* releasing a single key will then switch the
367+
* keyIsPressed property to true.
368+
* @private
369+
**/
370+
function areDownKeys() {
371+
for (var key in downKeys) {
372+
if (downKeys[key] === true ) {
373+
return true;
374+
}
375+
}
376+
return false;
377+
}
378+
357379
module.exports = p5;

0 commit comments

Comments
 (0)