Skip to content

Commit

Permalink
Update KeyHistory.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Sep 4, 2024
1 parent b6c640f commit 7edca6c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions featured/KeyHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@
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);
const key = Scratch.Cast.toString(event.key ?? "");
const lowerkey = key.toLowerCase();
if (!this.keysHit.includes(lowerkey)) {
this.keysHit.push(lowerkey);
this.keyHitTimes.push(Date.now());
}

Expand All @@ -207,16 +208,15 @@

// Convert the key to a string to ensure consistency
const key = Scratch.Cast.toString(event.key ?? "").toLowerCase();

// Find the index of the key in the keysDown array
const lowerkey = key.toLowerCase();
const index = this.keysDown.indexOf(key);

// Check if the key is actually in the array before trying to remove it
if (index !== -1) {
this.keysDown.splice(index, 1);
}

const hitIndex = this.keysHit.indexOf(key);
const hitIndex = this.keysHit.indexOf(lowerkey);

if (hitIndex !== -1) {
this.keysHit.splice(hitIndex, 1);
Expand Down

0 comments on commit 7edca6c

Please sign in to comment.