I have been for a long time now (4-5 months) been trying on and off to get JInput to work. I have installed it correctly, all of the testing programs work with my controller, but anytime I try to get poll data it is all either 0.0 for buttons, or -1.5258789E-5 for joysticks. Ive posted in the Jinput section of the forum but only got one answer that told me nothing but gave me code for another game (not an answer). Ive also posted on Stack Overflow with no avail. I have read through and followed the JInput getting started guide on this forum, along with looking anywhere I can on the internet to get something that might help me. All I find are dead links, links to the same tutorials I have already seen, or simply code for games that seems to do nothing different than me. I know this is the not the exact spot to be putting this post but I am getting desperate as nobody seems to visit that section of this forum anymore. Here is the code I am using to test my controller:
public class ControllerTest {
public static void main(String[] args){
ControllerTest test = new ControllerTest();
test.controllerTest();
}
void controllerTest(){
//System.out.println("Hello World");
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
Controller gamepad = null;
Component[] components = null;
// 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)){ // Snag the first instance of a 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("COMPONENTS:");
for(int i = 0; i < components.length; i ++){
StringBuffer buffer = new StringBuffer();
buffer.append("Component #" + i + ": "); // Get the Component #
buffer.append("\t" + components[i].getName()); // Get the component name
// Check if the component is analog or relative
// Relative relies on its past position for values
// Analog is a current position
// Analog absolute is a toggle (think your a,b,y,x button)
if(components[i].isRelative()){
buffer.append(" [Relative]");
}
else if(components[i].isAnalog()){
buffer.append(" [Analog]");
}
else{
buffer.append(" [Analog Absolute]");
}
System.out.println(buffer.toString());
}
}
else{
System.out.println("No gamepad connected");
}
float data = 0f;
while(gamepad.poll()){
for(int i = 0; i < components.length; i ++){
if(i == 0){
data = components[i].getPollData();
System.out.println(components[i].getName() + ": " + components[i].getPollData());
}
else if(i == 1){
data = components[i].getPollData();
System.out.println(components[i].getName() + ": " + components[i].getPollData());
}
else if(i == 4){
data = components[i].getPollData();
System.out.println(components[i].getName() + ": " + components[i].getPollData());
}
}
try{
Thread.sleep(20);
}
catch(Exception e){
e.printStackTrace();
}
}
System.out.println("Exited");
}
}
The reason I only print out the polled values of components[] at 0,1, and 4 is because those are the axis I am most interested in.
(I also realize I am not using the data variable for anything, I was simply using that variable for debugging)
Sorry for the long post, any help would be greatly appreciated.