Ah, apologies… the forum seems to have truncated my message. It should have included the following code from a class that extends a ThirdPersonHandler:
WeaponryInput weaponInputHandler = new WeaponryInput();
//Add action for button "1", to select weapon 1
this.addAction( weaponInputHandler, "Select Weapon: 1", KeyInput.KEY_1, false );
//Add action for button "1", to select weapon 1
this.addAction( weaponInputHandler, "Select Weapon: 2", KeyInput.KEY_2, false );
As you can see, I am assigning the 1 and 2 keys to the same instantiation of WeaponryInput. When these buttons are pressed, I get the empty print statement:
I recently fought with the same code. I found out that every ON_PRESS Event gives you the proper character but every ON_RELEASE Event comes up with something useless (I guess its this 0 character).
Is there a special reason for that? It would be easy enough to distinguish between the press and release event by getTriggerPressed(), wouldn't it? And it would be useful to know which key has been released?!
Monky said: I found out that every ON_PRESS Event gives you the proper character but every ON_RELEASE Event comes up with something useless (I guess its this 0 character).
Exactly. Pressing a key results in a character. Releasing does not. It's like this for most keyboard input events (awt, jinput, etc.) - it makes sense. If you need to distinguish the key you should use the key code - it is the same for pressed and released.
OK, not really understanding what is going on here… I've changed my code to:
public void performAction(InputActionEvent iActionEvent) {
if ( iActionEvent.getTriggerPressed() && iActionEvent.getTriggerCharacter() != 0 ) {
Character c = new Character (iActionEvent.getTriggerCharacter());
System.out.println("Weapon input handler received request from " + c + " key");
} else {
System.out.println("NOTHING");
}
}
And the console is giving me
NOTHING
NOTHING
NOTHING
NOTHING
NOTHING
When I repeatedly press the key I've assigned (numeric 1). Therefore, going by what is being said, you are implying that the ON_RELEASE event is being fired without the ON_PRESS event? Surely thats impossible?!?
looks like this:
public void addAction( InputActionInterface inputAction, String triggerCommand, int keyCode, boolean allowRepeats ) {
while the 'working' method looks like this:
public void addAction( InputActionInterface action, String deviceName, int button, int axis, boolean allowRepeats ) {
Have a look at the JavaDoc of those methods, as well. Only the second one triggers the action with device data.
The first method is using the old command system which does not pass characters at all. Maybe we should remove that old method or at least emphasize that there's a the different mechanism behind it...