Discuss Scratch

Interstellarninja
New Scratcher
9 posts

Problem with "any key pressed()"

After running this code on 2 different computers I could not get the specific sensing block “any key pressed()” to work in this program. Is there anything wrong with this?
whenclickedwait5secsifkey any pressed?thensayhellofor2secselsesaywrongfor2secs
MollyandMilodog
Scratcher
100+ posts

Problem with "any key pressed()"

Can you just use this block?

when any keypressed
Interstellarninja
New Scratcher
9 posts

Problem with "any key pressed()"

I am troubleshooting this part to use it in a larger program, so not exactly
MollyandMilodog
Scratcher
100+ posts

Problem with "any key pressed()"

You may have to use a lot of broadcasts
Interstellarninja
New Scratcher
9 posts

Problem with "any key pressed()"

yes, but I am trying to program a part so that when a user enters letter a, b, c, d … it will show sprites. Not sure if that would work?
Nambase_Test
Scratcher
35 posts

Problem with "any key pressed()"

whenclickedwait5secsforeverifkeyanypressed?thensayHello!for2secselsesayWrong!for2secsstopthis script stops the forever loop so code doesn't infinitely continue this loop will fix the issue

Last edited by Nambase_Test (April 30, 2020 17:20:43)

Interstellarninja
New Scratcher
9 posts

Problem with "any key pressed()"

It is still not working… I there should not be anything wrong with my laptop bc scratch is sensing when I use “when space clicked' but somehow not working when I use ”key any pressed()"?
Nambase_Test
Scratcher
35 posts

Problem with "any key pressed()"

Interstellarninja wrote:

It is still not working… I there should not be anything wrong with my laptop bc scratch is sensing when I use “when space clicked' but somehow not working when I use ”key any pressed()"?

I found the issue here.

When the wait(5) ends, the code checks for that single microsecond if any key is pressed, and no human can be that fast. So you need to change your code so it constantly keeps checking if the any key is clicked instead of it immediately inputting “wrong”.
Oumuamua
Scratcher
1000+ posts

Problem with "any key pressed()"

You need to be pressing constantly

Interstellarninja wrote:

After running this code on 2 different computers I could not get the specific sensing block “any key pressed()” to work in this program. Is there anything wrong with this?
whenclickedwait5secsifkey any pressed?thensayhellofor2secselsesaywrongfor2secs
You need to be pressing without releasing any key before 5 secs. passed(to detect key pressed), also the script will run one time only, so you can´t expect a wrong message if sprite aready said hello.

If you do the next script, and in case it detects a key being pressed, and you release the key before sprite ends saying hello the “wrong” will be activated:

whenclickedwait5secsifkeyanypressed?thensayhellofor2secsifnotkeyanypressed?thensaywrongfor2secs

Last edited by Oumuamua (April 30, 2020 18:28:31)

Interstellarninja
New Scratcher
9 posts

Problem with "any key pressed()"

Oh ok Thank you!
Is there any way to sense if any key was pressed and released within the three seconds and display the hello?

Last edited by Interstellarninja (April 30, 2020 18:49:27)

marcelzietek2006
Scratcher
500+ posts

Problem with "any key pressed()"

Interstellarninja wrote:

Oh ok Thank you!
Is there any way to sense if any key was pressed and released within the three seconds and display the hello?

you mean like this?
whenclickedforeverifkeyanypressed?thenresettimerwaituntilnotkeyanypressed?ortimer>3iftimer<3thensayHello!for2secs
Nambase_Test
Scratcher
35 posts

Problem with "any key pressed()"

Interstellarninja wrote:

Oh ok Thank you!
Is there any way to sense if any key was pressed and released within the three seconds and display the hello?

You could make a loop with a three-second wait block that also constantly checks if any key is clicked.

Powered by DjangoBB