Discuss Scratch
- wimpygirl6
-
61 posts
"Key Pressed" Sensor Reporter Block
WHOA!!!!!!Yes it does, also, I think it would be a better idea to use this than make a new block :3Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
Um, that's basically what I said don't do that, its called spam FYI
- ScratchDiogoh
-
1000+ posts
"Key Pressed" Sensor Reporter Block
Hello!
when green flag clickedMake all the keys
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
- Eli3210
-
21 posts
"Key Pressed" Sensor Reporter Block
I had the same idea and found a simple way to do so.
Use this script:
Sorry that Scratch didn't put the script together right.
(P.S: the “Any” variable has a value of “any”)
Use this script:
when green flag clickedEnjoy!
forever
if <key [ (item (Any)) of Key List pressed?> then
-your script goes here
end
end
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
-
1000+ posts
"Key Pressed" Sensor Reporter Block
I don't understand. Doesn't this block already exist?
I have a feeling I am missing something. Could someone please explain?
<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
-
1000+ posts
"Key Pressed" Sensor Reporter Block
Yes, this block exists, but the suggestion is about asking which keys are pressed, not if a key is pressed. Like this: 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?
(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
-
80 posts
"Key Pressed" Sensor Reporter Block
Sensing :: sensing hat
(Key Pressed :: sensing reporter)Yeah I had that idea too.
- Nambaseking01
-
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.
But I think Proli's system could give you a better understanding of how to recreate this in a simple manner.
- sathvikrias
-
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
-
100+ posts
"Key Pressed" Sensor Reporter Block
@sathvikrias that doesn't work, I see no reason it shouldn't though
- Futurebot5
-
1000+ posts
"Key Pressed" Sensor Reporter Block
That workaround is to long for how useful the suggestion is. 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
- bluedragon8633
-
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] ?> ?> thenNow, if you touch any enemy on the list, it broadcasts hurt, rather than doing this:
broadcast [hurt]
end
<<<touching [enemy1] ?>> or <<<touching [enemy2] ?>> or <<<touching [enemy3] ?>> or <<<touching [enemy4] ?>> or <<<touching [enemy5] ?>> or <touching [enemy6] ?>>>>>>
- sathvikrias
-
500+ posts
"Key Pressed" Sensor Reporter Block
I know, but at least it's less tedious That workaround is to long for how useful the suggestion is.
- ssvbxx2
-
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
-
49 posts
"Key Pressed" Sensor Reporter Block
There is a workaround Hi,https://scratch-mit-edu.ezproxyberklee.flo.org/projects/621656775/
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)]> thenInstead of having:
...
endif <<<<<key [... v] pressed?> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> thenAnd needing to repeat and change that every time you changed your mind.
...
end
Anybody else think that this is a good idea?
From Mad__Moss
However, its too limited and can cause a lot of lag, so support
- hai4a5
-
49 posts
"Key Pressed" Sensor Reporter Block
try mine @sathvikrias that doesn't work, I see no reason it shouldn't thoughhttps://scratch-mit-edu.ezproxyberklee.flo.org/projects/621656775/ (see inside)
- mcgoomba
-
1000+ posts
"Key Pressed" Sensor Reporter Block
<keys [space v] @delInput @addInput are pressed? :: sensing>//2.0is that what the block's gonna looks like?
<keys (space v) @delInput @addInput are pressed? :: sensing>//3.0
- Steve0Greatness
-
1000+ posts
"Key Pressed" Sensor Reporter Block
they're talking about<keys [space v] @delInput @addInput are pressed? :: sensing>//2.0is that what the block's gonna looks like?
<keys (space v) @delInput @addInput are pressed? :: sensing>//3.0
(key pressed :: sensing) //returns the last pressed key
like if I press
abcdqweryit would return “y.”
Last edited by Steve0Greatness (April 27, 2022 20:57:41)
- jjnxdjidshusdhusdyu
-
8 posts
"Key Pressed" Sensor Reporter Block
no block spamOk, thanks for the info.Yes it does, also, I think it would be a better idea to use this than make a new block :3Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
Um, that's basically what I said don't do that, its called spam FYImaybe this: Really? Anyone have more ideas on how the block would work?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:That way you could change the keys that need to be pressed more easily.
...
end
- GameFactory42
-
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)