Skip to content

Commit 45f6d7c

Browse files
authored
prepare for array changes to keysHeld
1 parent b729b27 commit 45f6d7c

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

p5.input.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
window.keysHeld = "";
1+
window.keysHeld = [];
22
window.theKey = "";
33
window.keysLog = "";
44
window.aKeyPressed = false;
55

6-
String.prototype.replaceAll = function (stringToFind, stringToReplace) {
6+
/*String.prototype.replaceAll = function (stringToFind, stringToReplace) {
77
if (stringToFind === stringToReplace) return this;
88
var temp = this;
99
// debug line
1010
// console.log((stringToFind.length > 0) + " and " + temp.includes(stringToFind))
1111
temp = (((stringToFind.length > 0) && temp.includes(stringToFind)) ? (temp.split(stringToFind).join(stringToReplace)) : (temp))
1212
return temp;
13-
};
13+
};*/
1414

1515
window.isHeld = function(_k) {
1616
return window.keysHeld.includes(_k);
1717
};
18+
window.getKeysHeldAsString = function() {
19+
return keysHeld.join('');
20+
};
1821
document.addEventListener('keydown', function (e) {
1922
window.theKey = e.key;
2023
window.keysLog += e.key;
2124
if(isHeld(e.key)) {
2225
return;
2326
}
2427
window.aKeyPressed = true;
25-
window.keysHeld = window.keysHeld.replaceAll(e.key, "");
28+
window.keysHeld = window.keysHeld.filter(key => (e.key !== key));
2629

27-
window.keysHeld += e.key;
30+
window.keysHeld.push(e.key);
2831
// testing
2932
// console.log(window.keysHeld);
3033
}
3134
);
3235
document.addEventListener('keyup', function (e) {
3336
window.theKey = e.key;
34-
window.keysHeld = window.keysHeld.replaceAll(e.key, "");
37+
window.keysHeld = window.keysHeld.filter(key => (e.key !== key));
3538
if(window.keysHeld.length <= 0) { window.aKeyPressed = false; }
3639
// testing
3740
//console.log(keysHeld);

0 commit comments

Comments
 (0)