Discuss Scratch

wimpygirl6
Scratcher
61 posts

"Key Pressed" Sensor Reporter Block

RPFluffy wrote:

Langdon35 wrote:

RPFluffy wrote:

MegaApuTurkUltra wrote:

Try some hacks

define keyPressesInList_allRequired
set [i v] to (1)
repeat (length of [presses v])
if <not<key (item (i) of [presses v]) pressed?>>
set [yes v] to (0) // idk if key pressed accepts a reporter. Try it! Otherwise edit the json
stop [this script v] // if not ALL keys in the list are pressed, return 0
end
change [i v] by (1)
end
set [yes v] to (1) // all keys in list pressed, return 1
define keyPressesInList_oneRequired
set [i v] to (1)
repeat (length of [presses v])
if <key (item (i) of [presses v]) pressed?>
set [yes v] to (1)
stop [this script v] // if at least ONE of the keys is pressed, return 1
end
change [i v] by (1)
end
set [yes v] to (0) // no keys in the list are pressed, return 0
The stop […] blocks are in there to prevent unnecessary looping, which will slow your project down. Make sure to use custom blocks like above because then stop this script will only stop the custom block. Also make sure to make the custom blocks run without screen refresh to speed up the looping.
Try this ^
It works…
Yes it does, also, I think it would be a better idea to use this than make a new block :3

Um, that's basically what I said don't do that, its called spam FYI
WHOA!!!!!!
ScratchDiogoh
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Hello!
when green flag clicked
forever
if <not <key [any v] pressed?>> then
delete (1 v) of [list v]
end
if <key [space v] pressed?> then
replace item (1 v) of [list v] with [space]
end

end
Make all the keys
Eli3210
Scratcher
21 posts

"Key Pressed" Sensor Reporter Block

I had the same idea and found a simple way to do so.
Use this script:
when green flag clicked
forever
if <key [ (item (Any)) of Key List pressed?> then
-your script goes here
end
end
Enjoy!
Sorry that Scratch didn't put the script together right.
(P.S: the “Any” variable has a value of “any”)

Last edited by Eli3210 (Aug. 23, 2019 22:25:55)

Nambaseking01
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

I don't understand. Doesn't this block already exist?

<key [c v] pressed?>

I have a feeling I am missing something. Could someone please explain?

Last edited by Nambaseking01 (Aug. 24, 2019 11:17:15)

46009361
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Nambaseking01 wrote:

I don't understand. Doesn't this block already exist?

<key [c v] pressed?>

I have a feeling I am missing something. Could someone please explain?
Yes, this block exists, but the suggestion is about asking which keys are pressed, not if a key is pressed. Like this:

(which keys pressed? :: sensing)

Anyway, I created a workaround for this block recently (which I commented on @CombaticonsCombine but then got deleted less than an hour after). The link to the project is:

https://scratch-mit-edu.ezproxyberklee.flo.org/projects/328947478/

Please check it out as it only has 2 views at the time of writing! There is even a discussion forum for this project at https://scratch-mit-edu.ezproxyberklee.flo.org/discuss/topic/369833/!

Edit: Be sure to give credit when you backpack my script! It's part of Scratch's Community Guidelines.

Last edited by 46009361 (Sept. 19, 2019 18:12:41)

PlayerXS
Scratcher
80 posts

"Key Pressed" Sensor Reporter Block

Sensing :: sensing hat
(Key Pressed :: sensing reporter)
Yeah I had that idea too.
Nambaseking01
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

I think this would be useful because a lot of people want it and the workaround is not the simplest for New Scratchers.

But I think Proli's system could give you a better understanding of how to recreate this in a simple manner.
sathvikrias
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

here is a workaround, which doesn't involve doing letter-for-letter:
define find key pressed
forever
if <key [any v] pressed?> then
set [keys v] to (keys you want to detect::undefined)
set [incroment v] to [1]
repeat (length of (keys)::operators)
if <key (letter (incroment) of (keys)) pressed?> then
set [key pressed v] to (letter (incroment) of (keys))
end
change [incroment v] by (1)
end
if <key (join [enter] []) pressed?> then
set [key pressed v] to [enter]
end
if <key [space v] pressed?> then
set [key pressed v] to [space]
end
say (key pressed)
else
say [no key is pressed]
end
end

Last edited by sathvikrias (Oct. 23, 2020 22:30:13)

moonwatcher348
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

@sathvikrias that doesn't work, I see no reason it shouldn't though
Futurebot5
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

sathvikrias wrote:

here is a workaround, which doesn't involve doing letter-for-letter:
define find key pressed
forever
if <key [any v] pressed?> then
set [keys v] to (keys you want to detect::undefined)
set [incroment v] to [1]
repeat (length of (keys)::operators)
if <key (letter (incroment) of (keys)) pressed?> then
set [key pressed v] to (letter (incroment) of (keys))
end
change [incroment v] by (1)
end
if <key (join [enter] []) pressed?> then
set [key pressed v] to [enter]
end
if <key [space v] pressed?> then
set [key pressed v] to [space]
end
say (key pressed)
else
say [no key is pressed]
end
end
That workaround is to long for how useful the suggestion is.
bluedragon8633
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Support, this also goes for touching sprites. If I have 10 different enemy sprites, it's easier to write
if <[enemy list] contains <touching [sprite] ?> ?> then
broadcast [hurt]
end
Now, if you touch any enemy on the list, it broadcasts hurt, rather than doing this:
<<<touching [enemy1] ?>> or <<<touching [enemy2] ?>> or <<<touching [enemy3] ?>> or <<<touching [enemy4] ?>> or <<<touching [enemy5] ?>> or <touching [enemy6] ?>>>>>>
sathvikrias
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

Futurebot5 wrote:

That workaround is to long for how useful the suggestion is.
I know, but at least it's less tedious
ssvbxx2
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Support. I made a document writing program, but since there's no reporter reporting which key is pressed, it's over 400 blocks. It would be useful for projects like that.
hai4a5
Scratcher
49 posts

"Key Pressed" Sensor Reporter Block

Mad__Moss wrote:

Hi,

I had an idea, what about a Sensor Reporter block that contained the key that was currently being pressed? If this existed, then you could have a list with all the keys that perform a specific function in it and make:
if <[Task 1 Keys v] contains [(key pressed)]> then
...
end
Instead of having:
if <<<<<key [... v] pressed?> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> then
...
end
And needing to repeat and change that every time you changed your mind.

Anybody else think that this is a good idea?

From Mad__Moss
There is a workaround https://scratch-mit-edu.ezproxyberklee.flo.org/projects/621656775/
However, its too limited and can cause a lot of lag, so support
hai4a5
Scratcher
49 posts

"Key Pressed" Sensor Reporter Block

moonwatcher348 wrote:

@sathvikrias that doesn't work, I see no reason it shouldn't though
try mine https://scratch-mit-edu.ezproxyberklee.flo.org/projects/621656775/ (see inside)
mcgoomba
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

<keys [space v] @delInput @addInput are pressed? :: sensing>//2.0
<keys (space v) @delInput @addInput are pressed? :: sensing>//3.0
is that what the block's gonna looks like?
Steve0Greatness
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

mcgoomba wrote:

<keys [space v] @delInput @addInput are pressed? :: sensing>//2.0
<keys (space v) @delInput @addInput are pressed? :: sensing>//3.0
is that what the block's gonna looks like?
they're talking about
(key pressed :: sensing) //returns the last pressed key

like if I press
abcdqwery
it would return “y.”

Last edited by Steve0Greatness (April 27, 2022 20:57:41)

jjnxdjidshusdhusdyu
Scratcher
8 posts

"Key Pressed" Sensor Reporter Block

Mad__Moss wrote:

Langdon35 wrote:

RPFluffy wrote:

Langdon35 wrote:

RPFluffy wrote:

MegaApuTurkUltra wrote:

Try some hacks

define keyPressesInList_allRequired
set [i v] to (1)
repeat (length of [presses v])
if <not<key (item (i) of [presses v]) pressed?>>
set [yes v] to (0) // idk if key pressed accepts a reporter. Try it! Otherwise edit the json
stop [this script v] // if not ALL keys in the list are pressed, return 0
end
change [i v] by (1)
end
set [yes v] to (1) // all keys in list pressed, return 1
define keyPressesInList_oneRequired
set [i v] to (1)
repeat (length of [presses v])
if <key (item (i) of [presses v]) pressed?>
set [yes v] to (1)
stop [this script v] // if at least ONE of the keys is pressed, return 1
end
change [i v] by (1)
end
set [yes v] to (0) // no keys in the list are pressed, return 0
The stop […] blocks are in there to prevent unnecessary looping, which will slow your project down. Make sure to use custom blocks like above because then stop this script will only stop the custom block. Also make sure to make the custom blocks run without screen refresh to speed up the looping.
Try this ^
It works…
Yes it does, also, I think it would be a better idea to use this than make a new block :3

Um, that's basically what I said don't do that, its called spam FYI
Ok, thanks for the info.

Mad__Moss wrote:

Really? Anyone have more ideas on how the block would work?
maybe this:
if <keys pressed> then //there would be a check box list of keys that could be pressed.
...
end

Or you could have a list with the keys you want to be pressed:
if <(item (all v) of [Key List v]) = [(key pressed)]> then //If ALL of the items in Key List are pressed then:
...
end
That way you could change the keys that need to be pressed more easily.
no block spam
GameFactory42
Scratcher
2 posts

"Key Pressed" Sensor Reporter Block

I support the idea of a “key pressed” or “active key” reporter block that returns a character (or some kind of null type if no key is down at the moment).

Last edited by GameFactory42 (June 20, 2022 00:39:28)

gdfsgdfsgdfg
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

bump cuz theres a dupe

Powered by DjangoBB