Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Ignore auto-repeated key presses #2

Merged
merged 1 commit into from

2 participants

@Sidnicious

If I hold down a key, the keydown event repeats and the note plays many times at once.

This works around the browser’s behavior by keeping track of which keys are down and only firing one callback per key until the key is released.

@stuartmemo
Owner

Awesome fix, thanks so much for this. Great username btw!

@stuartmemo stuartmemo merged commit 6bca917 into stuartmemo:master
@Sidnicious

:sparkles: YAY! :sparkles:

Though, I have mixed feelings about it. Holding down a key (pre-this-fix) and letting the oscillators build up for a few minutes make some AMAZING NOISES.

@stuartmemo
Owner

Haha, I know! Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2012
  1. @Sidnicious
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +4 −0 qwerty-hancock.js
View
4 qwerty-hancock.js
@@ -32,6 +32,7 @@
noteDown = false,
keyDownCallback,
keyUpCallback,
+ keysDown = {},
raphKeys = [],
raphSharpKeys = [],
newNotes = [];
@@ -190,6 +191,8 @@
}
var keyboardDown = function(key) {
+ if (key.keyCode in keysDown) return;
+ keysDown[key.keyCode] = true;
for (var i = 0; i < raphKeys.length; i++) {
if ((typeof keyToKey[key.keyCode] !== 'undefined') && (typeof raphKeys[i] !== 'undefined')) {
var keyPressed = keyToKey[key.keyCode].replace('l', qwertyOctave).replace('u', (parseInt(qwertyOctave, 10) + 1).toString());
@@ -212,6 +215,7 @@
};
var keyboardUp = function (key) {
+ delete keysDown[key.keyCode];
for (var i = 0; i < raphKeys.length; i++) {
if ((typeof keyToKey[key.keyCode] !== 'undefined') && (typeof raphKeys[i] !== 'undefined')) {
var keyPressed = keyToKey[key.keyCode].replace('l', qwertyOctave).replace('u', (parseInt(qwertyOctave, 10) + 1).toString());
Something went wrong with that request. Please try again.