Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to have something happen depending on how long you press a button
- Cradalack
- New Scratcher
2 posts
How to have something happen depending on how long you press a button
I want to have a code where you press down the space bar and it sets a variable to how long you hold down the button. Does anyone know how to do that? Ex. you hold the space bar for 0.7 seconds so variable x is set to 0.7/
- SupaYoshiBro
- Scratcher
100+ posts
How to have something happen depending on how long you press a button
Here ya go
when green flag clicked
forever
wait until <key [space v] pressed?>
repeat until <not <key [space v] pressed?>>
wait [0.001] secs
change [my variable v] by [0.001]
end
end
Last edited by SupaYoshiBro (Aug. 31, 2022 16:50:52)
Highlight the first letter of my signature
then shift+down arrow
Active griffpatcher
Goal: 300 posts (88% done, only 38 to go!)
when green flag clickedMy first post
repeat until <i quit scratch :: sensing>
eat :: motion
griffpatch for 15 hours straight :: extensions
aleep :: looks
end
My 10th post
My 20th post
My 25th post
My 40th post
My 50th post
My 60th post
My 100th post
My 150th post
My 200th post
My 250th post
when (::red) clicked :: operators hat
say [#A9EF01] :: looks
say [that color is fire] :: looks
Check out my profile here!
- legendary34678
- Scratcher
1000+ posts
How to have something happen depending on how long you press a button
If you want to set a variable to how long you held down a key, just do this:
when [space v] key pressed
reset timer
wait until <not <key [space v] pressed?>>
set [variable v] to (timer)
Can you beat my latest game?
Have you heard of the X Y Problem?
Please check out me projects please I'm desperate –> Idle Balls, Candy Grab!, Don't Move Your Mouse!, Rude Robot, Tic Tac Toe, Memory Game, Corn Maze, and Idle Balls PEN EDITION!
Oh, hey! I have 100+ posts now!
Oh, hey! I have 500+ posts now! (8/26/22)
Oh, hey! I have 1000+ posts now! (9/23/22)
(Thanks to @AntonL1kesPotato for helping me figure out how to add a signature!)
- Cradalack
- New Scratcher
2 posts
How to have something happen depending on how long you press a button
Thank you guys so much!
- Discussion Forums
- » Help with Scripts
- » How to have something happen depending on how long you press a button