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 426f702 commit 77c4362
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions featured/KeyHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
this.max_key_history = 100; // Adjust the maximum number of keys to keep in history
this.keybinds = ["Ctrl", "Shift", "Alt"];
this.keysDown = [];
this.keysHit = [];
this.pause = false;
}

Expand Down Expand Up @@ -135,6 +136,17 @@
},
},
},
{
opcode: "iskeyhit",
blockType: Scratch.BlockType.BOOLEAN,
text: "key [KEY] hit?",
arguments: {
KEY: {
type: Scratch.ArgumentType.STRING,
defaultValue: "a",
},
},
}
],
};
}
Expand Down Expand Up @@ -195,6 +207,12 @@
if (index !== -1) {
this.keysDown.splice(index, 1);
}

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

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


Expand Down Expand Up @@ -240,6 +258,17 @@
return this.keysDown.includes(Scratch.Cast.toString(KEY));
}

iskeyhit({ KEY }) {
KEY = Scratch.Cast.toString(KEY)
console.log(this.keysHit)
if (this.keysHit.indexOf(KEY) === -1) {
this.keysHit.push(KEY)
return true;
} else {
return false;
}
}

getKeysDown() {
return JSON.stringify(this.keysDown);
}
Expand Down

0 comments on commit 77c4362

Please sign in to comment.