Yeah a timer sounds good, but don’t use a while loop.
func _unhandled_input(event: InputEvent) -> void:
if event.is_action("action_shoot"):
if event.is_pressed():
$Timer.start()
# uncomment below to also shoot every press
#_on_timer_timeout()
elif event.is_released():
$Timer.stop()
func _on_timer_timeout() -> void:
# your shoot code
var new_proj1 = proj1.instantiate()
new_proj1.global_position = $Main_Gun.global_position
add_sibling(new_proj1)