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

why if released keys next time don t work anamation RUN ?

extends CharacterBody2D
@onready var anim = $AnimatedSprite2D
var speed = 5
var bow
var axe

func update():
if Input.is_action_pressed(“right”):
anim.play(“RUN”)
anim.flip_h = false
func update2():
if Input.is_action_pressed(“left”):
anim.play(“RUN”)
anim.flip_h = true
func update3():
if Input.is_action_just_released:
anim.play(“stay”)

func _physics_process(delta):

var  items = [bow,axe]
var one_item = items[0]
var two_item = items[1]

for item in items:
	print(" = ", item)

if Input.is_action_pressed("left"):
	position.x -= 1*speed
	update2()

if Input.is_action_pressed("right"):
	position.x += 1*speed
	update()
	
if Input.is_action_just_released:
	update3()

	move_and_slide()