public static void getFirstGamepadData() {
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
Controller firstGamepad = null;
for (int i = 0; i < controllers.length && firstGamepad == null; i++) {
if (controllers[i].getType() == Controller.Type.GAMEPAD) {
// Found a mouse
firstGamepad = controllers[i];
}
}
if (firstGamepad == null) {
// Couldn't find a mouse
System.out.println("Found no gamepad");
System.exit(0);
}
System.out.println("First gamepad is: " + firstGamepad.getName());
while (true) {
firstGamepad.poll();
Component[] components = firstGamepad.getComponents();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < components.length; i++) {
if (i > 0) {
buffer.append(", \n");
}
buffer.append(components[i].getName());
buffer.append(": ");
if (components[i].isAnalog()) {
buffer.append(components[i].getPollData());
} else {
if (components[i].getPollData() == 1.0f) {
buffer.append("On");
} else {
buffer.append("Off");
}
}
}
System.out.println(buffer.toString());
try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Using the code snippet above I only get:
Y Axis: -1.5258789E-5,
X Axis: -1.5258789E-5,
Y Rotation: -1.5258789E-5,
X Rotation: -1.5258789E-5,
Z Axis: -1.5258789E-5,
Axis 6: -1.5258789E-5,
Button 0: Off,
Button 1: Off,
Button 2: Off,
Button 3: Off,
Button 4: Off,
Button 5: Off,
Button 6: Off,
Button 7: Off,
Button 8: Off,
Button 9: Off,
Hat Switch: Off,
System Main Menu: Off
I am pretty sure I have the latest version of JInput and I am using an xbox one controller though this problem occurs for any device anyways. The test programs run fine and display correct readings for the gamepad and everything else. If I could see the source code for the test program that would probably help too.