Shooting 1 Arrow at a time

Hey guys, I my player to shoot an arrow in the game everytime you press the spacebar. However he always shoots 2 arrows. If i hold the spacebar he will shoot 1 untill released but if i regularly press it he shoots two. I have tried to used timers with the player animation time but those seem inconsistent.

This is my onAction method:
[java]
/**
* onAction method
*
* @param binding
* @param value
* @param tpf
*/
@Override
public void onAction(String binding, boolean value, float tpf) {
if (hp > 0) {
if (binding.equals(“Left”)) {

            left = value;
            legs.setAnim(walkAnim);
            legs.setSpeed(2f);
            legs.setLoopMode(LoopMode.Loop);
        } else if (binding.equals("Right")) {
            right = value;
            legs.setAnim(walkAnim);
            legs.setSpeed(2f);
            legs.setLoopMode(LoopMode.Loop);
        } else if (binding.equals("Up")) {
            up = value;
            legs.setAnim(walkAnim);
            legs.setSpeed(2f);
            legs.setLoopMode(LoopMode.Loop);
        } else if (binding.equals("Down")) {
            down = value;
            legs.setAnim(walkAnim);
            legs.setSpeed(2f);
            legs.setLoopMode(LoopMode.Loop);

        } else if (binding.equals("Attack")) {
            attack = value;
            game.getItem().createArrow(assetManager, bulletAppState);

}
[/java]

And this is my createArrow method:

[java]
/**
* createArrow method - srrow is spawned when the player is range class and
* press space.
*/
public void createArrow(AssetManager assetManager, BulletAppState bulletAppState) {
arrow = assetManager.loadModel(“Models/Player/Range/arrow.j3o”);
arrow.setMaterial(assetManager.loadMaterial(“Models/Player/Range/arrowMaterial.j3m”));

    arrowHitBox = new GhostControl(new BoxCollisionShape(new Vector3f(2f, 2f, 2f)));

    arrows = new Node();
    arrow.scale(2f);
    arrow.setLocalTranslation(game.getPlayer().getWorldTranslation().add(new Vector3f(0, 6, 0)));
    arrow.setLocalRotation(game.getPlayer().getLocalRotation());
    arrow.rotate(3.15f, 0, 0);
    arrowShape = CollisionShapeFactory.createBoxShape(arrow);
    arrowPhysics = new RigidBodyControl(arrowShape);
    arrowPhysics.setLinearVelocity(game.getApp().getCamera().getDirection().multLocal(new Vector3f(200, 10, 200)));
    arrow.addControl(arrowPhysics);
    arrows.attachChild(arrow);
    arrow.addControl(arrowHitBox);
    arrows.setLocalTranslation(game.getPlayer().getLocalTranslation().add(new Vector3f(0, 0, 2).mult(1.8f).addLocal(new Vector3f(0, 0, 2).mult(0.9f))));

    arrowStreak =
            new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
    Material mat_red = new Material(assetManager,
            "Common/MatDefs/Misc/Particle.j3md");
    mat_red.setTexture("Texture", assetManager.loadTexture(
            "Effects/spark.png"));
    arrowStreak.setMaterial(mat_red);
    arrowStreak.setImagesX(2);
    arrowStreak.setImagesY(2); // 2x2 texture animation
    arrowStreak.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));   // red
    arrowStreak.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow
    arrowStreak.setLocalTranslation(arrow.getLocalTranslation());
    arrowStreak.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
    arrowStreak.setStartSize(1.5f);
    arrowStreak.setEndSize(0.1f);
    arrowStreak.setGravity(0, 0, 0);
    arrowStreak.setLowLife(1f);
    arrowStreak.setHighLife(3f);
    arrowStreak.getParticleInfluencer().setVelocityVariation(0.3f);
    game.getApp().getRootNode().attachChild(arrowStreak);

    bulletAppState.getPhysicsSpace().add(arrowPhysics);
    bulletAppState.getPhysicsSpace().add(arrowHitBox);
    game.getApp().getRootNode().attachChild(arrows);
}//end of createArrow method

[/java]

TL;DR I want my player to shoot 1 arrow everytime he presses spacebar, currently is shoot 2 arrows at the same time.

You must check the state of the key event (pressed or not) if you don’t add this check, the arrow will be shot when pressed and released.

@jonesadev said: You must check the state of the key event (pressed or not) if you don't add this check, the arrow will be shot when pressed and released.
Understood, ill search for a keyPressed in API or something similar.

EDIT:I fixed it, by adding !value to a conditional statement in my onAction method.