How to make the ActionListener perform repeat an action *while* a key is pressed

Can anyone point to a way to do this? Because with the regular ActionListener Class, and onAction, whatever it is I want it to do only performs once. For Example, I may have

> inputManager.addMapping(“Ups”, new KeyTrigger(KeyInput.KEY_W));
> inputManager.addListener(this, “Ups”);

somewhere in the code.

And in the onAction() method I have

> if (binding.equals(“Ups”)) {
> accelerationForce = accelerationForce + 5;
> vehicle.accelerate(accelerationForce);
> System.out.println(“acceleration”);
> }

This only runs whatever’s in the if once, understandably.

How do I make it so it will whatever’s in the if while the button is held, and stop running when it is let go. And maybe even do this when let go:

> vehicle.accelerate(0);

Set some boolean to true when the key is pressed, do whateveryou want repeated in update() while that is true, set it to false when they key is depressed and perform your end action.

1 Like

Thanks very much!

If you don’t mind, I do have another problem.

I followed this tutorial:

And the box in the middle, that connects the wheels, the BoxCollisionShape doesn’t show up, it’s there, I can tell, but it is invisible. And I cannot add a material to it. So how do I get past this? Thanks.