Skip to content

Commit 94db40d

Browse files
committed
Arrow keys now work, ASCII ones do not
1 parent 48b1d00 commit 94db40d

File tree

7 files changed

+13
-8
lines changed

7 files changed

+13
-8
lines changed

TODOs/bugs.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
- [x] Keypress event block should be marked as not ran only when the last block in the script is done
66
- [x] Use block.top to detect the event which needs to be marked
77
- [x] Wait blocks below key events don't work
8+
- [x] Key repeat doesn't apply
89

910
## ❎ In progress
1011

1112
- [ ] Keys which have ASCII codes don't work
12-
- [ ] Cannot use multiple event handlers for one key
13+
- [ ] Revisit keypress checks
14+
- [ ] Empty key events set (all keys!)
15+
- [ ] Cannot use multiple event handlers for one key

assets/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"targets":[{"isStage":true,"name":"Stage","variables":{"`jEk@4|i[#Fk?(8x)AV.-my variable":["variabila mea",0]},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"assetId":"cd21514d0531fdffb22204e0ec5ed84a","name":"decor1","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","dataFormat":"svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[{"assetId":"83a9787d4cb6f3b7632b4ddfebf74367","name":"pop","dataFormat":"wav","format":"","rate":44100,"sampleCount":1032,"md5ext":"83a9787d4cb6f3b7632b4ddfebf74367.wav"}],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":null},{"isStage":false,"name":"Personaj1","variables":{},"lists":{},"broadcasts":{},"blocks":{"Fu(KfOuh$cmgs0~Auqf9":{"opcode":"event_whenflagclicked","next":"%8(CtQom@,Qrk`;X+c1P","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":233,"y":241},"%YFU}CY;=s+fot2avH}*":{"opcode":"control_repeat","next":"bsblJ:MFwOOpBeuK5bD{","parent":"/%kBdd{_YGZu*[n3aMhW","inputs":{"TIMES":[1,[6,"10"]],"SUBSTACK":[2,"}IRk2OYvn4PF,G6N;b*O"]},"fields":{},"shadow":false,"topLevel":false},"%8(CtQom@,Qrk`;X+c1P":{"opcode":"motion_gotoxy","next":null,"parent":"Fu(KfOuh$cmgs0~Auqf9","inputs":{"X":[1,[4,"0"]],"Y":[1,[4,"0"]]},"fields":{},"shadow":false,"topLevel":false},"8K@.:@oW0!FH}1Q1nVCE":{"opcode":"control_repeat","next":null,"parent":"bsblJ:MFwOOpBeuK5bD{","inputs":{"TIMES":[1,[6,"10"]],"SUBSTACK":[2,"H=wW]C.G5jmE3UatxMgw"]},"fields":{},"shadow":false,"topLevel":false},"bsblJ:MFwOOpBeuK5bD{":{"opcode":"control_wait","next":"8K@.:@oW0!FH}1Q1nVCE","parent":"%YFU}CY;=s+fot2avH}*","inputs":{"DURATION":[1,[5,"0.5"]]},"fields":{},"shadow":false,"topLevel":false},"}IRk2OYvn4PF,G6N;b*O":{"opcode":"motion_changeyby","next":null,"parent":"%YFU}CY;=s+fot2avH}*","inputs":{"DY":[1,[4,"10"]]},"fields":{},"shadow":false,"topLevel":false},"H=wW]C.G5jmE3UatxMgw":{"opcode":"motion_changeyby","next":null,"parent":"8K@.:@oW0!FH}1Q1nVCE","inputs":{"DY":[1,[4,"-10"]]},"fields":{},"shadow":false,"topLevel":false},"/%kBdd{_YGZu*[n3aMhW":{"opcode":"event_whenkeypressed","next":"%YFU}CY;=s+fot2avH}*","parent":null,"inputs":{},"fields":{"KEY_OPTION":["space",null]},"shadow":false,"topLevel":true,"x":235,"y":401}},"comments":{},"currentCostume":0,"costumes":[{"assetId":"b7853f557e4426412e64bb3da6531a99","name":"costum1","bitmapResolution":1,"md5ext":"b7853f557e4426412e64bb3da6531a99.svg","dataFormat":"svg","rotationCenterX":48,"rotationCenterY":50},{"assetId":"e6ddc55a6ddd9cc9d84fe0b4c21e016f","name":"costum2","bitmapResolution":1,"md5ext":"e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg","dataFormat":"svg","rotationCenterX":46,"rotationCenterY":53}],"sounds":[{"assetId":"83c36d806dc92327b9e7049a565c6bff","name":"Miau","dataFormat":"wav","format":"","rate":44100,"sampleCount":37376,"md5ext":"83c36d806dc92327b9e7049a565c6bff.wav"}],"volume":100,"layerOrder":1,"visible":true,"x":0,"y":0,"size":100,"direction":90,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"0.2.0-prerelease.20201016122132","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Scratch/3.18.1 Chrome/80.0.3987.165 Electron/8.2.5 Safari/537.36"}}
1+
{"targets":[{"isStage":true,"name":"Stage","variables":{"`jEk@4|i[#Fk?(8x)AV.-my variable":["variabila mea",0]},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"name":"decor1","dataFormat":"svg","assetId":"cd21514d0531fdffb22204e0ec5ed84a","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[{"name":"pop","assetId":"83a9787d4cb6f3b7632b4ddfebf74367","dataFormat":"wav","format":"","rate":44100,"sampleCount":1032,"md5ext":"83a9787d4cb6f3b7632b4ddfebf74367.wav"}],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"Personaj1","variables":{},"lists":{},"broadcasts":{},"blocks":{"Fu(KfOuh$cmgs0~Auqf9":{"opcode":"event_whenflagclicked","next":"%8(CtQom@,Qrk`;X+c1P","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":233,"y":241},"%YFU}CY;=s+fot2avH}*":{"opcode":"control_repeat","next":"bsblJ:MFwOOpBeuK5bD{","parent":"/%kBdd{_YGZu*[n3aMhW","inputs":{"TIMES":[1,[6,"10"]],"SUBSTACK":[2,"}IRk2OYvn4PF,G6N;b*O"]},"fields":{},"shadow":false,"topLevel":false},"%8(CtQom@,Qrk`;X+c1P":{"opcode":"motion_gotoxy","next":null,"parent":"Fu(KfOuh$cmgs0~Auqf9","inputs":{"X":[1,[4,"0"]],"Y":[1,[4,"0"]]},"fields":{},"shadow":false,"topLevel":false},"8K@.:@oW0!FH}1Q1nVCE":{"opcode":"control_repeat","next":null,"parent":"bsblJ:MFwOOpBeuK5bD{","inputs":{"TIMES":[1,[6,"10"]],"SUBSTACK":[2,"H=wW]C.G5jmE3UatxMgw"]},"fields":{},"shadow":false,"topLevel":false},"bsblJ:MFwOOpBeuK5bD{":{"opcode":"control_wait","next":"8K@.:@oW0!FH}1Q1nVCE","parent":"%YFU}CY;=s+fot2avH}*","inputs":{"DURATION":[1,[5,"0.5"]]},"fields":{},"shadow":false,"topLevel":false},"}IRk2OYvn4PF,G6N;b*O":{"opcode":"motion_changeyby","next":null,"parent":"%YFU}CY;=s+fot2avH}*","inputs":{"DY":[1,[4,"10"]]},"fields":{},"shadow":false,"topLevel":false},"H=wW]C.G5jmE3UatxMgw":{"opcode":"motion_changeyby","next":null,"parent":"8K@.:@oW0!FH}1Q1nVCE","inputs":{"DY":[1,[4,"-10"]]},"fields":{},"shadow":false,"topLevel":false},"/%kBdd{_YGZu*[n3aMhW":{"opcode":"event_whenkeypressed","next":"%YFU}CY;=s+fot2avH}*","parent":null,"inputs":{},"fields":{"KEY_OPTION":["a",null]},"shadow":false,"topLevel":true,"x":235,"y":401}},"comments":{},"currentCostume":0,"costumes":[{"name":"costum1","bitmapResolution":1,"dataFormat":"svg","assetId":"b7853f557e4426412e64bb3da6531a99","md5ext":"b7853f557e4426412e64bb3da6531a99.svg","rotationCenterX":48,"rotationCenterY":50},{"name":"costum2","bitmapResolution":1,"dataFormat":"svg","assetId":"e6ddc55a6ddd9cc9d84fe0b4c21e016f","md5ext":"e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg","rotationCenterX":46,"rotationCenterY":53}],"sounds":[{"name":"Miau","assetId":"83c36d806dc92327b9e7049a565c6bff","dataFormat":"wav","format":"","rate":44100,"sampleCount":37376,"md5ext":"83c36d806dc92327b9e7049a565c6bff.wav"}],"volume":100,"layerOrder":1,"visible":true,"x":0,"y":0,"size":100,"direction":90,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"1.0.1","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36"}}

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Project file name
3131
# If the "manual" mode is chosen, set the Scratch project file to load.
32-
projectFileName: str = "projects/KeyTest1alt.sb3"
32+
projectFileName: str = "projects/KeyTest1alt3.sb3"
3333

3434
# Extract on project run
3535
# Set whether to extract the project assets on run.

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def buttonbox(self):
309309
toExecute.append(nextBlock)
310310

311311
if e.opcode == "event_whenkeypressed":
312-
print(s.target.blocks, e.script)
312+
# print(s.target.blocks, e.script)
313313
if not e.script or all(s.target.blocks[b].blockRan for b in e.script):
314314
e.blockRan = False
315315
for b in e.script:
52.7 KB
Binary file not shown.

projects/KeyLogger.sb3

41.3 KB
Binary file not shown.

scratch.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import targetSprite
1414
import bs4
1515
import time
16+
from datetime import datetime
1617

1718
i18n.set("locale", config.language)
1819
i18n.set("filename_format", "{locale}.{format}")
@@ -214,15 +215,15 @@ def execute(block, s, keys=set(), keyEvents=set()):
214215
pass
215216

216217
elif opcode == "event_whenkeypressed":
217-
print("Handling key event")
218+
# print("Handling key event")
218219
# if not block.waiting:
219220
# # Get time delay and convert it to milliseconds
220221
# block.timeDelay = 500
221222
# block.waiting = True
222223
# block.executionTime = 0
223224
# print("DEBUG: Waiting for", block.timeDelay, "ms")
224225
key = block.getFieldValue("key_option", lookIn=0)
225-
print(key)
226+
# print(key)
226227

227228
if key == "any": # when key [any v] pressed
228229
# TODO any key
@@ -270,7 +271,8 @@ def execute(block, s, keys=set(), keyEvents=set()):
270271
nextBlock = s.target.blocks[block.next]
271272
return nextBlock
272273
else:
273-
print(f"Unknown event: { key } in { keyEvents }, all keys: { keys }")
274+
# print(f"Unknown event: { key } in { keyEvents }, all keys: { keys }")
275+
pass
274276

275277
block.blockRan = False
276278
return None
@@ -395,7 +397,7 @@ def execute(block, s, keys=set(), keyEvents=set()):
395397
if config.showSALogs:
396398
# These are Scratch Addons debugger blocks.
397399
if block.proccode == "​​log​​ %s": # Scratch Addons log ()
398-
print(_("project-log"), block.getCustomInputValue(0), file=sys.stderr)
400+
print("[", datetime.now().strftime("%H:%M:%S:%f"), "]", _("project-log"), block.getCustomInputValue(0), file=sys.stderr)
399401
elif block.proccode == "​​warn​​ %s": # Scratch Addons warn ()
400402
print(_("project-warn"), block.getCustomInputValue(0), file=sys.stderr)
401403
elif block.proccode == "​​error​​ %s": # Scratch Addons error ()

0 commit comments

Comments
 (0)