Discuss Scratch

EDawg2011
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

whenrightkeypressedmove10steps

If you hold down right for a second, there's a slight pause after the first frame, then it continues. This is SO weird. Why is it even like this? I need answers.
106809nes
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

EDawg2011 wrote:

whenrightkeypressedmove10steps

If you hold down right for a second, there's a slight pause after the first frame, then it continues. This is SO weird. Why is it even like this? I need answers.
You know how you hold down a key and it has a slight delay before going like “gggggggggggggggggggggg” until you stop pressing the key? That's the same with the Arrow keys.
PhiPhenomenon
Scratcher
500+ posts

Why is the "when key pressed" block so weird?

I expect it's intended since inexperienced Scratchers would learn how to use hat blocks before booleans. They might not know about how fast Scratch runs yet. The small delay would help with interpreting what's going on with these users, as it's obvious that one key press leads to one movement output. If there were no delay on the block, it could confuse a few new Scratchers why their sprite moves more than they expected it to.
InfiniteBlackHole
Scratcher
11 posts

Why is the "when key pressed" block so weird?

If you want no delay, you can use
whenclickedforeverifkeyRight arrow keypressed?thenmove10steps
or
whenRight arrow keykeypressedrepeatuntilnotkeyRight arrow keypressed?move10steps
Scratch137
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

As you know, it's possible to type a single character rapidly by holding down its key on the keyboard. However, many operating systems insert a delay after the key is pressed down before it begins to repeat. This is done to ensure that a single keypress, when not held down, will only type a single character.

Scratch's “when key pressed” block reads this input as the operating system interprets it; thus, the repeat delay specified in your keyboard settings applies to Scratch as well.

The “key pressed?” block, on the other hand, reads a raw input directly from the keyboard. This input is not subject to any repeat delay, and so it immediately begins to repeat as fast as possible.
Vaibhs11
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

Scratch137 wrote:

Scratch's “when key pressed” block reads this input as the operating system interprets it; thus, the repeat delay specified in your keyboard settings applies to Scratch as well.
Correct.
element.onkeydown = function(e) {
if (e.key == "ArrowRight") {...} // if key pressed do that
}                                // [also fires on key repeat when held down]

Scratch137 wrote:

The “key pressed?” block, on the other hand, reads a raw input directly from the keyboard. This input is not subject to any repeat delay, and so it immediately begins to repeat as fast as possible.
I don't think so, it's more like this:
element.onkeydown = function(e) {
if (e.key == "ArrowRight") {return true} // if key pressed boolean is true
}
element.onkeyup = function(e) {
if (e.key == "ArrowRight") {return false} // if key lifted boolean is false
}

Last edited by Vaibhs11 (Jan. 3, 2024 12:52:22)

cookieclickerer33
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

whenkeypressedrepeatuntilnotkeypressed?. . .
Vaibhs11
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

cookieclickerer33 wrote:

whenkeypressedrepeatuntilnotkeypressed?. . .
OP is asking about the pause between the repeat, not for solutions.
cookieclickerer33
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

Vaibhs11 wrote:

cookieclickerer33 wrote:

whenkeypressedrepeatuntilnotkeypressed?. . .
OP is asking about the pause between the repeat, not for solutions.
I’m aware, I just wanted to make sure they knew there was a way arround it as it seemed to me like this was an issue in one of their programs

For an answer of why think of the block as running every time the letter is typed, not just when the key is pressed
So pressing the key once will trigger the hat once, twice will twice etc. but holding it will type one letter then wait a little before spamming the letter. So basically
whenkeypressed
Triggers whenever the letter selected is typed by the keybord. And
keypressed?
Is true whenever the key selected is pressed down at all
EDawg2011
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

InfiniteBlackHole wrote:

whenRight arrow keykeypressedrepeatuntilnotkeyRight arrow keypressed?move10steps
Hey, I learned that trick from watching CS First.
106809nes
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

EDawg2011 wrote:

InfiniteBlackHole wrote:

whenRight arrow keykeypressedrepeatuntilnotkeyRight arrow keypressed?move10steps
Hey, I learned that trick from watching CS First.
Stay on topic!
josueart
Scratcher
500+ posts

Why is the "when key pressed" block so weird?

You can also use the Makey Makey extension if you don't want to code that boilerplaté everytime you need to detect presses.

whenspacekeypressed

Huh, 2.0 doesn't have the makey makey extension.
gdfsgdfsgdfg
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

josueart wrote:

You can also use the Makey Makey extension if you don't want to code that boilerplaté everytime you need to detect presses.

whenspacekeypressed

Huh, 2.0 doesn't have the makey makey extension.
try using extension color or pen color to simulate a extension

Last edited by gdfsgdfsgdfg (Jan. 3, 2024 13:37:05)

Vaibhs11
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

gdfsgdfsgdfg wrote:

try using extension color or pen color to simulate a extension
#0fbd8c

extensionhatblock
EDawg2011
Scratcher
1000+ posts

Why is the "when key pressed" block so weird?

106809nes wrote:

Stay on topic!
Sorry.

Powered by DjangoBB