Skip to content

Commit

Permalink
Update KeyHistory.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Aug 31, 2024
1 parent 77c4362 commit 1d57104
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions featured/KeyHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
this.keybinds = ["Ctrl", "Shift", "Alt"];
this.keysDown = [];
this.keysHit = [];
this.keyHitTimes = [];
this.pause = false;
}

Expand Down Expand Up @@ -179,8 +180,12 @@

onKeyDown(event) {
Scratch.vm.runtime.startHats('KeyHistoryExtension_onKeyPressed');

const key = Scratch.Cast.toString(event.key ?? "").toLowerCase();
if (!this.keysHit.includes(key)) {
this.keysHit.push(key);
this.keyHitTimes.push(Date.now());
}

// Only add the key if it's not already in keysDown
if (!this.keysDown.includes(key)) {
Expand Down Expand Up @@ -212,6 +217,7 @@

if (hitIndex !== -1) {
this.keysHit.splice(hitIndex, 1);
this.keyHitTimes.splice(hitIndex, 1);
}
}

Expand Down Expand Up @@ -260,10 +266,12 @@

iskeyhit({ KEY }) {
KEY = Scratch.Cast.toString(KEY)
console.log(this.keysHit)
if (this.keysHit.indexOf(KEY) === -1) {
this.keysHit.push(KEY)
return true;
let hit = this.keysHit.indexOf(KEY);
if (hit !== -1) {
let out = false
out = ((Date.now() - this.keyHitTimes[hit]) < 100)
this.keyHitTimes[hit] = 0;
return out;
} else {
return false;
}
Expand Down

0 comments on commit 1d57104

Please sign in to comment.