How to make a key release wait

Godot Version

4.2 Mono

Question

I have a bow and arrow. I want to make the following logic for the bow:
If the attack button is pressed:
Start charging the bow, after
If the attack button is held down, wait for the button to be released, after the
Shot.
I have written the following code for this:

private async void shoot()
{
    this.Play("Charge", attackSpeedMultiplier);
    await ToSignal(this, AnimatedSprite2D.SignalName.AnimationFinished);

    while (Input.IsActionPressed("lcm"))
    {

    }

    this.Play("Shoot", attackSpeedMultiplier);
    await ToSignal(this, AnimatedSprite2D.SignalName.AnimationFinished);
    this.Play("Idle");
    
    ProjectileComponent projectile = new ProjectileComponent(projectileSettings, GlobalPosition, GetGlobalMousePosition());
    addProjectiles(projectile);
}

When I attack and I don’t hold down the key. Everything goes as it should: Loaded - Shot, but when I hold it down, the game just stops. Please help me

P.S. The script is located in the AnimatedSprite2D node

The while loop stops the game. You can use Input.is_action_just_released() to know when the action is released.

Split the function in two one for the charge() and one for the actual shoot() and don’t call the shoot() function until the action has been released.

I’ve not tested it but something like this:

var charging:bool = false


func _process(delta:float) -> void:
	if Input.is_action_just_pressed("lcm"):
		charge()
	
	if charging and Input.is_action_just_released("lcm"):
		shoot()
		
		
func charge() -> void:
	play("charge")
	await animation_finished
	charging = true
	
	
func shoot() -> void:
	charging = false
	# the rest