Discuss Scratch
- FANTASTICMRF0X
-
2 posts
(keys pressed?) block
Another idea would be Scratch reporting every key pressed in a list. For example, if I press keys X and Y, then Scratch would add them to the list, and when I let go of them, they would be deleted.
If I want to sense key X, then I would have this:
“if <(item (any) of |Key Pressed|)
X)> then…”
And to sense two or more it would be this:
“if <<(item (any) of |Key Pressed|)
X)>and<(item (any) of |Key Pressed|)
Y)>> then…”
(sorry Scratchblocks doesn't work for me)
If I want to sense key X, then I would have this:
“if <(item (any) of |Key Pressed|)
![](http://cdn.scratch.mit.edu/scratchr2/static/__f3d308221474a0b7409d8752452b362b__/djangobb_forum/img/smilies/sad.png)
And to sense two or more it would be this:
“if <<(item (any) of |Key Pressed|)
![](http://cdn.scratch.mit.edu/scratchr2/static/__f3d308221474a0b7409d8752452b362b__/djangobb_forum/img/smilies/sad.png)
![](http://cdn.scratch.mit.edu/scratchr2/static/__f3d308221474a0b7409d8752452b362b__/djangobb_forum/img/smilies/sad.png)
(sorry Scratchblocks doesn't work for me)
Last edited by FANTASTICMRF0X (Oct. 19, 2017 23:52:43)
THE LEGEND OF ZELDA:
The Platformer ~V2.0
/\
/ \
/ \
/ \
/ \
/______\
/\______/\
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/______\/______\
\______/\______/
- IloveHolly
-
39 posts
(keys pressed?) block
here: https://scratch.mit.edu/projects/184614148/ it just uses a pretty simple technique using a hacked block. ![](//cdn.scratch.mit.edu/scratchr2/static/__edeeb9742280669f2eae661e72ce5d5d__/djangobb_forum/img/smilies/smile.png)
![](http://cdn.scratch.mit.edu/scratchr2/static/__edeeb9742280669f2eae661e72ce5d5d__/djangobb_forum/img/smilies/smile.png)
wait until <[Hamsters] = [Awesome]>
say [What's the point of that wait block? They never aren't awesome.]
Check out the best game of all time! Awesomeness in a box
- Charles12310
-
1000+ posts
(keys pressed?) block
Even though this is useful for a typing system…
It's long, but you can do this:
foreverAlso, what if more than one key is pressed?
if <key [any v] pressed?> then
wait until <not <key [any v] pressed?>>
set [text v] to (join (text)(key pressed :: sensing))
end
end
<(key pressed::sensing) = [l]>
<(key pressed::sensing) = [o]>
<(key pressed::sensing) = [s]>
<(key pressed::sensing) = [e]>
<(key pressed::sensing) = [r]>
It's long, but you can do this:
when green flag clicked
forever
if <key [space v] pressed?> then
set [key v] to [space]
else
if <key [a v] pressed?> then
set [key v] to [a]
else
...
end
end
end
![](http://i.cubeupload.com/b6JYap.png)
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
- reallyrandonperson
-
16 posts
(keys pressed?) block
I totally support this.
when gf clicked
forever
if <[1]=[2]> then
play sound [explosion v] until done
stop [all v]
end
- Charles12310
-
1000+ posts
(keys pressed?) block
I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor. There can also be reporters such as:
This is so incase more than one key is pressed.
For example, if you are trying to simulate a question and answer system:
((1 v) of pressed keys :: sensing )
(number of keys pressed :: sensing )
This is so incase more than one key is pressed.
For example, if you are trying to simulate a question and answer system:
define ask (q) and wait
set [ans v] to []
repeat until <<mouse down?> and <touching [mouse reporter v]?>>
wait until <key [any v] pressed?>
set [key v] to ((1 v) of pressed keys :: sensing ) // if there are any other keys being pressed during the time then they will
wait until <not <key [any v] pressed?>> // be ignored. The system will detect what is being pressed first.
set [ans v] to (join (ans)(key))
end
Last edited by Charles12310 (Dec. 10, 2017 18:49:05)
![](http://i.cubeupload.com/b6JYap.png)
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
- walkcycle
-
500+ posts
(keys pressed?) block
super creative, but what happens with the list of key presses over time . . . does it keep growing? I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor.
- DaEpikDude
-
1000+ posts
(keys pressed?) block
Presumably once the key's no longer pressed it's deleted from the list?super creative, but what happens with the list of key presses over time . . . does it keep growing? I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor.
And all the world over, each nation's the same,
They've simply no notion of playing the game.
They argue with umpires, they cheer when they've won,
And they practice beforehand, which ruins the fun!
- Charles12310
-
1000+ posts
(keys pressed?) block
Yeah. Here is an example of how this could work:Presumably once the key's no longer pressed it's deleted from the list?super creative, but what happens with the list of key presses over time . . . does it keep growing? I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor.
if <<key [space v] pressed?> and <not <[keys pressed v] contains [space]?>>> then
wait until <not <key [space v] pressed?>>
set [index v] to [0]
repeat until <(item (index) of [keys pressed v]) = [space]>
change [index v] by (1)
end
delete (index) of [keys pressed v]
end
![](http://i.cubeupload.com/b6JYap.png)
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
- walkcycle
-
500+ posts
(keys pressed?) block
wow, that looks like you could make a project that would do this without maybe even changing scratch?Yeah. Here is an example of how this could work: Presumably once the key's no longer pressed it's deleted from the list?if <<key [space v] pressed?> and <not <[keys pressed v] contains [space]?>>> then
wait until <not <key [space v] pressed?>>
set [index v] to [0]
repeat until <(item (index) of [keys pressed v]) = [space]>
change [index v] by (1)
end
delete (index) of [keys pressed v]
end
- TomasBento
-
1 post
(keys pressed?) block
Don't notice this comment ok??
Last edited by TomasBento (Nov. 25, 2017 22:24:27)
- CrystalScratchCat
-
38 posts
(keys pressed?) block
or maybe this!!
when green flag clicked
forever
if <key [r v] pressed> then
switch costume to [ me v]
end
Last edited by CrystalScratchCat (Nov. 26, 2017 16:14:10)
when green flag clicked
if <(CrystalScratchCat) = (Followed)> then
say [Thank u] for (2) secs
broadcast [orange juice v]
end
if <(CrystalScratchCat) = <not (Followed)>> then
broadcast [Summon a lemon in your room v]
say [F O L L O W M E] for (2) secs
end
- CAT_SPRITE
-
19 posts
(keys pressed?) block
There is, but we would like to see scratch implement it into the editor instead of us either getting it from another hacked project or changing the code ourselves. there are hacked blocks about that, but ok
support
(Life)
- --Waterfall--
-
500+ posts
(keys pressed?) block
Yes, that makes more sense then the original suggestion. I like the ‘last letter pressed’ idea.That's a good question. I think an unambiguous one (that would clearly have some limitations) is: What if multiple keys are pressed? What would it report?
Say the key “r” was pressed. Obviously, the block would report “r”
But if both “r” and “g” are pressed, the block wouldn't be “r” anymore, so<(keys pressed::sensing)=[r]>Wouldn't work even though the r key is being pressed.
And how'll the cursor keys, enter/return, backspace/delete, delete/delete, and ctrl/command/shift/alt/option/etc. be reported via this block?(last letter pressed :: sensing)
- CrystalScratchCat
-
38 posts
(keys pressed?) block
![](http://cdn.scratch.mit.edu/scratchr2/static/__c89b951732bd8a9ec34d48bde86c1116__/djangobb_forum/img/smilies/cool.png)
when green flag clicked
forever
if< <key [b v]pressed?> and <key [g v] pressed?>> then
switch costume to [CrystalScratchCat Playing v]
end
end
Last edited by CrystalScratchCat (Dec. 2, 2017 04:28:59)
when green flag clicked
if <(CrystalScratchCat) = (Followed)> then
say [Thank u] for (2) secs
broadcast [orange juice v]
end
if <(CrystalScratchCat) = <not (Followed)>> then
broadcast [Summon a lemon in your room v]
say [F O L L O W M E] for (2) secs
end
- Jun-Dragon
-
61 posts
(keys pressed?) block
Workaround:if <key [r v] pressed?> then
... :: grey
end
Basically that script would only work if you pressed “r”. What if you wanted to change the key you pressed?
if <(key pressed:: sensing) = (key)> then
your stuff :: grey
end
This would be so much better
Last edited by Jun-Dragon (Dec. 10, 2017 19:07:54)
- Code_Spawner
-
2 posts
(keys pressed?) block
I support. This would make things so much easier - instead of doing
when green flag clickedand then repeat that 25 more times. Very good idea!
forever
if <> then
<key [a] pressed?>
set [text] to (join (foo) [a])
end
end
- powercon5
-
1000+ posts
(keys pressed?) block
Especially with 3.0, there's a much easier way. I support. This would make things so much easier - instead of doingwhen green flag clickedand then repeat that 25 more times. Very good idea!
forever
if <> then
<key [a] pressed?>
set [text] to (join (foo) [a])
end
end
You can use something like this
define Key pressed
set [Key pressed v] to []
set [i v] to [0]
repeat (length of [ qwertyuiopasdfghjklzxcvbnm1234567890])
change [i v] by (1)
if <key (letter (i) of [ qwertyuiopasdfghjklzxcvbnm1234567890]) pressed?> then
set [key pressed v] to (letter (i) of [ qwertyuiopasdfghjklzxcvbnm1234567890])
stop [this script v]
end
end
Witty signature.
- StrangeMagic32
-
1000+ posts
(keys pressed?) block
No support, it's easy enough to just do
if <key [a v] pressed?> then::events
set [text v] to (join (text) [a])
end
if <key [b v] pressed?> then::events
set [text v] to (join (text) [b])
end
if <key [c v] pressed?> then::events
set [text v] to (join (text) [c])
end
...::events
Last edited by StrangeMagic32 (Feb. 1, 2019 01:56:22)
“Remember the worth of souls is great in the sight of God;”
- Doctrine and Covenants 18:10
I have since moved to @JollyWinter