I am attempting to create a simple test program to get familiar with the JInput Library for another project. I have tested my controller with the all of the provided test classes and it works as expected. However, when I attempt to poll the controller, all values remain unchanged regardless of my input. Here is the code I am working with:
public class ControllerTest {
public static void main(String[] args){
//System.out.println("Hello World");
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
Controller gamepad = null;
Component[] components = null;
EventQueue eventQueue;
// Run through the list of available input devices and get the gamepad
for(int i = 0; i < ca.length; i ++){
if(ca[i].getType().equals(Controller.Type.GAMEPAD)){
gamepad = ca[i];
}
}
// Print the name of the controller and its type
if(gamepad != null){
System.out.println(gamepad.getName() + ": " + gamepad.getType());
components = gamepad.getComponents();
System.out.println("\tComponents:");
for(int i = 0; i < components.length; i ++){
System.out.println("\t\tComponent #" + i + ": " + components[i].getName() + "\n\t\t\tIs Relative: "
+ components[i].isRelative());
}
}
else{
System.out.println("No gamepad connected");
}
while (true){
// If we have no gamepad connected, exit
if(gamepad == null){
System.out.println("No Gamepad detected, exiting...");
System.exit(0);
}
// Poll controller
gamepad.poll();
Component[] comp = gamepad.getComponents();
for(int i = 0; i < comp.length; i ++){
StringBuffer buffer = new StringBuffer();
buffer.append(comp[i].getName());
buffer.append(", Value: " + comp[i].getPollData());
System.out.println(buffer.toString());
}
try{
Thread.sleep(20); // Sleep before polling again
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
I have been trying to find an answer online, but this library is not very well documented and seems to usually be wrapped in other libraries specific for making games. (The aforementioned project is robotic in nature)