Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » Why is the "when key pressed" block so weird?
- EDawg2011
-
1000+ posts
Why is the "when key pressed" block so weird?
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
-
1000+ posts
Why is the "when key pressed" block so weird?
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.
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.
- PhiPhenomenon
-
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
-
11 posts
Why is the "when key pressed" block so weird?
If you want no delay, you can use
or
- Scratch137
-
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.
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
-
1000+ posts
Why is the "when key pressed" block so weird?
Correct. 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.
element.onkeydown = function(e) { if (e.key == "ArrowRight") {...} // if key pressed do that } // [also fires on key repeat when held down]
I don't think so, it's more like this: 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.
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)
- Vaibhs11
-
1000+ posts
Why is the "when key pressed" block so weird?
OP is asking about the pause between the repeat, not for solutions.
- cookieclickerer33
-
1000+ posts
Why is the "when key pressed" block so weird?
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 programsOP is asking about the pause between the repeat, not for solutions.
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
Triggers whenever the letter selected is typed by the keybord. And
Is true whenever the key selected is pressed down at all
- EDawg2011
-
1000+ posts
Why is the "when key pressed" block so weird?
Hey, I learned that trick from watching CS First.
- 106809nes
-
1000+ posts
Why is the "when key pressed" block so weird?
Stay on topic!Hey, I learned that trick from watching CS First.
- josueart
-
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.
Huh, 2.0 doesn't have the makey makey extension.
Huh, 2.0 doesn't have the makey makey extension.
- gdfsgdfsgdfg
-
1000+ posts
Why is the "when key pressed" block so weird?
try using extension color or pen color to simulate a extension You can also use the Makey Makey extension if you don't want to code that boilerplaté everytime you need to detect presses.
Huh, 2.0 doesn't have the makey makey extension.
Last edited by gdfsgdfsgdfg (Jan. 3, 2024 13:37:05)
- Vaibhs11
-
1000+ posts
Why is the "when key pressed" block so weird?
#0fbd8c try using extension color or pen color to simulate a extension
- Discussion Forums
- » Questions about Scratch
-
» Why is the "when key pressed" block so weird?