Skip to content

Commit d2fd9d8

Browse files
committed
More Key Inputs
1 parent 53223e3 commit d2fd9d8

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

features/features.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "more-key-inputs",
5+
"versionAdded": "v3.7.0"
6+
},
27
{
38
"version": 2,
49
"id": "comment-tags",

features/more-key-inputs/data.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": "More Key Inputs",
3+
"description": "Adds support for more keys on \"key pressed\" blocks.",
4+
"credits": [
5+
{
6+
"username": "o0blackbat0o",
7+
"url": "https://scratch.mit.edu/users/o0blackbat0o/"
8+
},
9+
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
10+
],
11+
"type": ["Editor"],
12+
"tags": ["New", "Featured"],
13+
"scripts": [{ "file": "script.js", "runOn": "/projects/*" }]
14+
}

features/more-key-inputs/script.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export default async function ({ feature, console }) {
2+
const NEW_ITEMS = ["enter", "-", "[", "]", "\\", ".", ",", "'", ";", "`"];
3+
4+
ScratchTools.waitForElements(
5+
"g.blocklyDraggable[data-shapes='reporter boolean']",
6+
function (block) {
7+
if (!feature.self.enabled) return;
8+
if (!Blockly) return;
9+
10+
block = Blockly.getMainWorkspace().getBlockById(block.dataset.id);
11+
if (!block) return;
12+
13+
if (block.type === "sensing_keypressed") {
14+
let child = block.childBlocks_[0];
15+
if (child.type === "sensing_keyoptions") {
16+
let menu = child.inputList[0].fieldRow[0].menuGenerator_;
17+
18+
for (var i in NEW_ITEMS) {
19+
if (!menu.find((item) => item[0] === NEW_ITEMS[i])) {
20+
menu.push([NEW_ITEMS[i], NEW_ITEMS[i]]);
21+
}
22+
}
23+
}
24+
}
25+
}
26+
);
27+
28+
ScratchTools.waitForElements(
29+
"g.blocklyDraggable[data-shapes='hat']",
30+
function (block) {
31+
if (!feature.self.enabled) return;
32+
if (!Blockly) return;
33+
34+
block = Blockly.getMainWorkspace().getBlockById(block.dataset.id);
35+
if (!block) return;
36+
37+
if (block.type === "event_whenkeypressed") {
38+
let menu = block.inputList[0].fieldRow[1].menuGenerator_;
39+
40+
for (var i in NEW_ITEMS) {
41+
if (!menu.find((item) => item[0] === NEW_ITEMS[i])) {
42+
menu.push([NEW_ITEMS[i], NEW_ITEMS[i]]);
43+
}
44+
}
45+
}
46+
}
47+
);
48+
}

0 commit comments

Comments
 (0)