Joystick Buttons Confusion

Hi,

I’m testing with a Playstation 3 Controller. The axes work correct. But the buttons do not seem to trigger an action.
Example:
[java]
Joystick[] joysticks = inputManager.getJoysticks();
Joystick joy = joysticks[0];
JoystickAxis axis = axes.get(0);
axis.assignAxis(“right”, “left”); // works
List<JoystickButton> buttons = joy.getButtons();
buttons.get(10).assignButton(“fire”); // does not work
[/java]
By “does not work” I mean that the corresponding “onAction” method is never called.

However, if I’m using a RawInputListener the events are there.
[java]
inputManager.addRawInputListener(new RawInputListener() {
@Override
public void beginInput() {
}
@Override
public void endInput() {
}
@Override
public void onJoyAxisEvent(JoyAxisEvent evt) {
}
@Override
public void onJoyButtonEvent(JoyButtonEvent evt) {
System.out.println(evt.getButton());
}
@Override
public void onMouseMotionEvent(MouseMotionEvent evt) {
}
@Override
public void onMouseButtonEvent(MouseButtonEvent evt) {
}
@Override
public void onKeyEvent(KeyInputEvent evt) {
}
@Override
public void onTouchEvent(TouchEvent evt) {
}
});
[/java]
Output:
[java]
JoystickButton[name=Base 6, parent=PLAYSTATION®3 Controller, id=11, logicalId=Base 6]
JoystickButton[name=Base 6, parent=PLAYSTATION®3 Controller, id=11, logicalId=Base 6]
JoystickButton[name=Base 5, parent=PLAYSTATION®3 Controller, id=10, logicalId=Base 5]
JoystickButton[name=Base 5, parent=PLAYSTATION®3 Controller, id=10, logicalId=Base 5]
[/java]

@niclas.hoyer said: By "does not work" I mean that the corresponding "onAction" method is never called.

Well, I can’t see how you are registering your action listener so it’s tough to comment on what could be wrong.

assignButton() doesn’t do much magic, though:
[java]
public void assignButton(String mappingName) {
inputManager.addMapping(mappingName, new JoyButtonTrigger(parent.getJoyId(), buttonIndex));
}
[/java]

I found the problem. As I only connected one controller, I assumed that the number of joysticks recognized by jMonkey would be one. It turns out that the joystick appears twice using getJoysticks:
[java]
Joysticks: 2
0: Joystick[name=PLAYSTATION®3 Controller, id=0, buttons=13, axes=27]
1: Joystick[name=PLAYSTATION®3 Controller, id=1, buttons=13, axes=27]
[/java]

If I bind everything using the second one (index 1), it seems to work.

The controller is registered as “/dev/input/js0” (linux). I don’t know why it is listed twice. Maybe the jInput library uses several methods to find controllers.