Is there a way to measure how quickly a key was pressed (while still holding it down after pressing)?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Kair0ss

To clarify I’m making a simple platform fighter (think Smash Bros) and I want to have the character walk and run using the same keys. I decided on making them run if the key is pressed quickly and walk if it’s pressed slowly (the keys I’m using are A and D for left and right respectively). And thus we come back to the title question.

BTW I’m super new to this engine/ GDScript so I’d appreciate as much detail as you care to give. Thank you in advance.

I don’t think it’s possible for a computer to know how fast you hit the button.

Merlin1846 | 2020-03-03 15:42

Indeed, all common keyboards out there have digital input, which means each key has an “all or nothing” strength. This is in contrast to gamepads or the elusive analog keyboards.

Calinou | 2020-03-05 10:03

So like Krippi said. Just use something like double tap or even a shift button combined with walking to either run or walk.

Merlin1846 | 2020-03-05 15:20

Had a feeling this was the case, thanks for clarifying. I intend to have gamepad support as well so I just went with having a sprint key for keyboard.

Kair0ss | 2020-03-05 17:50

:bust_in_silhouette: Reply From: Krippi

I think you can’t press a button quickly and slowly. But you can ask whether a button holds for 1 second and then let the player run instead of walk.

Or you do it with D = walk and double D = run. So a double click.

Do you mean this?

If I went for something like this I would just have a run button to be held in conjunction as I don’t like double tapping, thanks anyway.

Kair0ss | 2020-03-04 03:28