How to check how much an imput button has been pressed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Noob_Maker
:warning: Old Version Published before Godot 3 was released.

I want to do something like this:Imgur: The magic of the Internet
The thing is I want to say, “if Right movement or Left movement is true, check how much one is being pressed” I looked in the Doc but it doesn’t say anything on checking the input. How do you that? I think it’s something like Left.check (Left is my variable for going left) but I’m not sure. :confused:

:bust_in_silhouette: Reply From: avencherus

If you’re dealing with dashing, counting key presses is probably not an easy way to do it, since there is timing. If you go the polling route and your frame rate is 60 FPS, it’s going to test for that condition every 1/60th of a second.

I would recommend using some threshold of time between the last key press and release.

A basic example would look like this:

func _ready():
	set_fixed_process(true)
	
var previously_pressed = false
var time_count = 0
	
const ALLOWED_DELAY = .2 # Seconds

func _fixed_process(delta):

	if(Input.is_key_pressed(KEY_SPACE)): 
		if(not previously_pressed): 
			if(time_count <= ALLOWED_DELAY):
				dash_action()
			time_count = 0
		previously_pressed = true
		
	else:
		previously_pressed = false
	
	time_count += delta
	
func dash_action():
	print("Dashing")