How to put a timer for your keyboard input?

Hey everyone!

I have a quick question I think is easy to answer but I still can’t find how I can do that… In some fighting games and even action-RPGs, there are actions which strength is determined by how long you keep the input pressed, or the action changes depending on if you either tap the button or keep it pressed. Do you know any on how I can do that?

Have a great day everyone!

Hello!

To achieve what you wanted using logic nodes, you can use the “On Keyboard” node,

The “Down” option means the key is kept pressed
The"Started" option means the key is pressed just once.

You may use these nodes along with the “Timer” node to keep track of the timing as needed.

1 Like

Hey,

I am new to Armory so this was a great way for me to get some experience with the API’s.

class ButtonController extends iron.Trait {

var timePressed: Float = 0;

public function new() {
super();

  var kb = new Keyboard();

  // notifyOnInit(function() {
  // });

  notifyOnUpdate(function() {
  	if (kb.down("space")) 
  		timePressed += Time.delta;

  	if (kb.released("space")) {
  		kb.reset();
  		if(timePressed > 0)
  			trace(timePressed);
  			timePressed = 0;
  	}
  });

}

1 Like

Apologies I didn’t notice this was in the Logic Nodes section.