Issue Finding Controllers (Solved)

Hi everyone. First off, I’m excited to use JInput, it looks like a lot of work has gone into it and I’m pretty impressed with what I’ve used so far. I’m attempting to integrate an Xbox360 controller into a project i’m working on and using the jinput-test.jar I can press buttons, move the joystick etc etc. Interestingly enough, it’s also showing the USB Mouse attached to my computer.

However, when I get a controller list using this standard method:



ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] controllers = ce.getControllers();

for( int i = 0; i < controllers.length; i++ )
{
    Print(controllers[i].getType().toString(), true);
}


it only finds my laptop keyboard and mouse, none of the USB devices that are plugged in. I’m on Vista 32 and like I said, most everything appears to be working. Is the source for jinput-test.jar available anywhere? That would be a good start but I couldn’t find it on the CVS or anywhere else.

Any help on what I’m doing wrong or a push in the right direction would be much appreciated!
Thanks!

Hi

You can find the source for JInput here. The stuff that ends up in the jinput-test.jar is coreAPI/src/java/net/java/games/input/test/.

You mention the 360 controller and then say nothing plugged in via USB is recognised, what else is plugged in but not recognised?

The 360 controller is a wierd one as microsoft decided that directx wasn’t good enough for it, and introduced xinput (not to be confused with xinput, the input interface under X windows). JInput doesn’t support either xinputs as yet. I believe there is also a directx driver for the 360 controller, but I don’t think it supports 100% of the controllers functionality.

Cheers

Endolf

I think I may have discovered a large part of the problem, although I’m not sure how to fix it.

First of all, the other USB device found is the attached USB mouse (when I run jinput-test.jar using the suggested method shown below)


java -Djava.library.path=. -cp jinput.jar;jinput-test.jar net.java.games.input.test.ControllerReadTest

What’s interesting, is that I’m doing my development inside netbeans for now, in which I called the ControllerReadTest function from within my own main. When it launches, it too shows only my laptop mouse and keyboard. Similiarly, when I launch the automatically generated JAR file from double clicking it in windows explorer, the ControllerReadTest window pops up, but this time there are no controllers found. This must be related to netbeans?

I have the necessary .dlls and JAR files appended to the values in my main PATH variable. Do you have any suggestions, particularly for development in netbeans? There must be a link i’m missing. I added the file to the classpath and imported it as a local library (which worked, when adding it to the classpath did not).

Anyway, thanks for taking this up! I appreciate it. Look forward to hearing back :slight_smile:

also, in case I wasn’t 100% clear, when I run the ControllerReadTest(); in, say, C:\JInput, it works excellent. The XBox controller is found and it reports the status of everything to me.

It is when I run it from inside, say netbeans that nothing plugged in via USB is found.

Any idea? Thanks!

*** Update ***
Okay, so I gave something a shot (with my limited understanding of what’s happening here).

I modified the runline to be:


java -Djava.library.path=C:\JInput\ -cp C:\Users\...\NetBeansProjects\XBoxController\dist\XBoxController.jar MainJFrame

And it worked perfectly, XBox 360 controller and all. This same project (exact same file) run inside netbeans does not give the same results. So…

What this indicates to me is that I need to set the java.library.path for this project somehow? I would guess that question is unrelated to actual JInput issues but if someone wouldn’t mind helping me then I’m sure some peole would find it useful. I’ll be happy to throw a little guide to making JInput work easily with Netbeans if you would like. That’s especially useful for newbies like myself :slight_smile:

Hi

the native files (dlls on windows) are loaded by the JVM from java.library.path. This must be set to the folder containing the files at runtime. I havn’t used netbeans for years, so I have no idea how to set it.

A quick google suggests you can pass properties to the ant command that launches the project in netbeans, the one your after is the java.library.path, this needs to be set to the folder containing the natives for your platform.

HTH

Endolf

Okay, my problem was solved. A rested pair of eyes helps tremendously.

There are two ways to get the natives (dll’s) to work with netbeans. There may be more, but these are definitly sufficient, at least for now.

  1. Netbeans Specific:
    Right-click your project -> Properties -> click on “Run” -> Under VM Option’s type: -Djava.library.path=C:\JInput // this was where my JInput files resided.

  2. Generic:
    Copy and paste all .dlls into your C:\Windows or C:\Windows\System32 folder

Anyway, I appreciate all your help Endolf. I’m looking forward to using this thing now :slight_smile:

Please don’t do number 2, it will cause all sorts of headaches if you try applets or other versions of JInput :slight_smile:

Endolf