Discuss Scratch

turkey3
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

You may want to insert symbols into the key sensing block like this:
if <key [/ v] pressed?>
...
But the drop-down menu does not offer the capability to do so. This tutorial goes step-by-step on how to manually change it through JSON modification.

How To

In Scratch, have the key sensing block all set and in place where you want it. Then go to File > Download to your computer in the online editor or File > Save as in the offline editor.

At the end of the name, add
.zip

Then, access where you saved the file, and it will be compressed into a zipped folder. Then, right-click on the zipped folder and select “Extract all”. Save it to the default folder when prompted.

Find the folder with the extracted files; they should be in the same location as the zipped project is.

Open that folder and scroll to the very bottom; open the JSON file by right-clicking and selecting Open with > Notepad, or any other text editor.

Depending on the text editor you use, the text may be organized or scattered. No worried! Hit ctrl-f and search for
keyPressed

It should highlight the code for the block as shown above. Then, to the right of it will be the key that the block senses. Change it to any symbol you like! Keep it in the quotation marks. When done, hit ctrl-s to save and exit out. Then go back to the folder where the zipped files were extracted, right-click on the folder, and go to Send to > Zipped archive

Open the new compress file in the Scratch offline editor, and tada! The key you changed is in the block.

Edit: You can manually rename the file extension to .sb2

Last edited by turkey3 (Aug. 23, 2014 13:21:27)

blob8108
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

turkey3
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

blob8108 wrote:

Is this not the same as http://scratch.mit.edu/discuss/topic/1810/unread/ ?
Well, sort of, but this isn't for custom blocks. I guess they could be merged if need be.

And this uses more pictures
ppettitt
Scratcher
100+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Awesome! This will be very helpful for me in the future!
But I do have one question; how would I get the ENTER key in there?
Would this work:
<key [enter v] pressed?>
or would I need to do this:
<key [return v] pressed?>
Or is it not possible to get Scratch to detect the ENTER key?
turkey3
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

ppettitt wrote:

Awesome! This will be very helpful for me in the future!
But I do have one question; how would I get the ENTER key in there?
Would this work:
<key [enter v] pressed?>
or would I need to do this:
<key [return v] pressed?>
Or is it not possible to get Scratch to detect the ENTER key?
I am not sure, I have tried but failed. Those keys may be different on different keyboards, so I guess there would maybe be some code to resemble them.

Last edited by turkey3 (Feb. 14, 2014 21:37:59)

Botond2003
Scratcher
3 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

I know how to make scratch sense the enter key!
All you need to is to make a script like this: when green flag is clicked, forever, ask (…) and wait and then send a message that the enter key is pressed.
So whenever you get a message ‘enter key is pressed’ you can make your sprites do something!
Isn't that creative?
And you can cover the blue box with a sprite in front of it.

Thanks for reading.
turkey3
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Botond2003 wrote:

I know how to make scratch sense the enter key!
All you need to is to make a script like this: when green flag is clicked, forever, ask (…) and wait and then send a message that the enter key is pressed.
So whenever you get a message ‘enter key is pressed’ you can make your sprites do something!
Isn't that creative?
And you can cover the blue box with a sprite in front of it.

Thanks for reading.
That's not exactly what I'm looking for. I'm talking
if <key [enter v] pressed?>
...
end
derpmeup
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Thanks! This helped!
themusicmanooo
Scratcher
69 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

when it says find i put keyPress but it says it cant find it i tried up down and match case but it still cant find
turkey3
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

themusicmanooo wrote:

when it says find i put keyPress but it says it cant find it i tried up down and match case but it still cant find
Those are already built into Scratch!
themusicmanooo
Scratcher
69 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

turkey3 wrote:

themusicmanooo wrote:

when it says find i put keyPress but it says it cant find it i tried up down and match case but it still cant find
Those are already built into Scratch!
really what about
<key [shift v] pressed?>  <key [tab v] pressed?>
those dont exist in scratch! i meant at the text editor

Last edited by themusicmanooo (Aug. 23, 2014 04:17:29)

derpmeup
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

derpmeup wrote:

Thanks! This helped!
Nice guide, I'm going to request this to be stickied or iTopiced - I'll let the mods choose
Znapi
Scratcher
500+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

@griffpatch 's project has some blocks that detect enter key and other keys. They are in a
<key [ v] pressed?>
block. I don't know if they work for all keyboards. I think they do, because whatever code they use for those keys is part of a universal language.
EDIT: Yeah, it just uses \r. That should work on all keyboards. It is the browser's job to handle keyboards.

Last edited by Znapi (Nov. 20, 2014 23:53:00)

Mamu10
Scratcher
52 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

ppettitt wrote:

Awesome! This will be very helpful for me in the future!
But I do have one question; how would I get the ENTER key in there?
Would this work:
<key [enter v] pressed?>
or would I need to do this:
<key [return v] pressed?>
Or is it not possible to get Scratch to detect the ENTER key?
You will need to enter the special character which means “enter” or “return”. See http://scratch.mit.edu/projects/19199766/ by Griffpatch to get blocks which sense special keys.

Last edited by Mamu10 (Nov. 27, 2014 20:25:00)

cheeseeater
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Nice guide, thanks for sharing the knowledge.

Last edited by cheeseeater (Jan. 24, 2015 15:29:21)

MegaApuTurkUltra
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Cool tut!
ChocolatePi
Scratcher
1000+ posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

turkey3 wrote:

ppettitt wrote:

Awesome! This will be very helpful for me in the future!
But I do have one question; how would I get the ENTER key in there?
Would this work:
<key [enter v] pressed?>
or would I need to do this:
<key [return v] pressed?>
Or is it not possible to get Scratch to detect the ENTER key?
I am not sure, I have tried but failed. Those keys may be different on different keyboards, so I guess there would maybe be some code to resemble them.

perhaps

 ["keypress", '\r'] 
???
yugi1024
Scratcher
30 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

ppettitt wrote:

Awesome! This will be very helpful for me in the future!
But I do have one question; how would I get the ENTER key in there?
Would this work:
<key [enter v] pressed?>
or would I need to do this:
<key [return v] pressed?>
Or is it not possible to get Scratch to detect the ENTER key?
I know. In the JSON file, in the “ ”, click inbetween it, and just press enter. It would look weird, but I swear, it works.
For proof, go here for my hacked blocks and go inside.
yugi1024
Scratcher
30 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Enter the <key pressed?> boolean in your project, then do what Turkey3 said (saves me a lot of explaining).
In the code, find this:
["keyPressed:", "space"],
Delete the “space”. Should look like:
["keyPressed:", ""],
Go in between the two quotation marks and press Enter:
["keyPressed:", "
"],
It works. I swear.

Last edited by yugi1024 (Dec. 1, 2014 02:05:04)

yugi1024
Scratcher
30 posts

Tutorial: Hacking to Insert Symbols into Key Press Blocks

Then upload it on your project again and there should be:
<key[ v] pressed?>
Except that it should be fatter then that (at least that's what happened to me).

Powered by DjangoBB