Discuss Scratch

jellyrmaker
Scratcher
95 posts

(keys pressed?) block

there are hacked blocks about that, but ok
support

FANTASTICMRF0X
Scratcher
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)

Last edited by FANTASTICMRF0X (Oct. 19, 2017 23:52:43)


THE LEGEND OF ZELDA:
The Platformer ~V2.0

/\
/ \
/ \
/ \
/ \
/______\
/\______/\
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/______\/______\
\______/\______/
IloveHolly
Scratcher
39 posts

(keys pressed?) block

here: https://scratch.mit.edu/projects/184614148/ it just uses a pretty simple technique using a hacked block.

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
Scratcher
1000+ posts

(keys pressed?) block

Even though this is useful for a typing system…

forever
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]>
Also, what if more than one key is pressed?

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


A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
reallyrandonperson
Scratcher
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
Scratcher
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:

((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)



A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
walkcycle
Scratcher
500+ posts

(keys pressed?) block

Charles12310 wrote:

I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor.
super creative, but what happens with the list of key presses over time . . . does it keep growing?
DaEpikDude
Scratcher
1000+ posts

(keys pressed?) block

walkcycle wrote:

Charles12310 wrote:

I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor.
super creative, but what happens with the list of key presses over time . . . does it keep growing?
Presumably once the key's no longer pressed it's deleted from the list?

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
Scratcher
1000+ posts

(keys pressed?) block

DaEpikDude wrote:

walkcycle wrote:

Charles12310 wrote:

I have a solution to this. Instead of key pressed being just a reporter, it is going to use a list as a monitor.
super creative, but what happens with the list of key presses over time . . . does it keep growing?
Presumably once the key's no longer pressed it's deleted from the list?
Yeah. Here is an example of how this could work:

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


A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
walkcycle
Scratcher
500+ posts

(keys pressed?) block

Charles12310 wrote:

DaEpikDude wrote:

Presumably once the key's no longer pressed it's deleted from the list?
Yeah. Here is an example of how this could work:

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
wow, that looks like you could make a project that would do this without maybe even changing scratch?
TomasBento
Scratcher
1 post

(keys pressed?) block

Don't notice this comment ok??

Last edited by TomasBento (Nov. 25, 2017 22:24:27)

walkcycle
Scratcher
500+ posts

(keys pressed?) block

TomasBento wrote:

Don't notice this comment ok??
Okay
CrystalScratchCat
Scratcher
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
Scratcher
19 posts

(keys pressed?) block

jellyrmaker wrote:

there are hacked blocks about that, but ok
support
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.

(Life)
--Waterfall--
Scratcher
500+ posts

(keys pressed?) block

TheMonsterOfTheDeep wrote:

Sheep_maker wrote:

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?
That's a good question. I think an unambiguous one (that would clearly have some limitations) is:
(last letter pressed :: sensing)
Yes, that makes more sense then the original suggestion. I like the ‘last letter pressed’ idea.


CrystalScratchCat
Scratcher
38 posts

(keys pressed?) block

then this:

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
Scratcher
61 posts

(keys pressed?) block

Ziggy741 wrote:

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
Scratcher
2 posts

(keys pressed?) block

I support. This would make things so much easier - instead of doing
when green flag clicked
forever
if <> then
<key [a] pressed?>
set [text] to (join (foo) [a])
end
end
and then repeat that 25 more times. Very good idea!
powercon5
Scratcher
1000+ posts

(keys pressed?) block

Code_Spawner wrote:

I support. This would make things so much easier - instead of doing
when green flag clicked
forever
if <> then
<key [a] pressed?>
set [text] to (join (foo) [a])
end
end
and then repeat that 25 more times. Very good idea!
Especially with 3.0, there's a much easier way.
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
Scratcher
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

Powered by DjangoBB