Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Issue Finding Controllers (Solved)  (Read 2104 times)
0 Members and 1 Guest are viewing this topic.
Offline forfor573

Junior Newbie

« Posted 2009-04-20 07:10:32 »

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!
Offline endolf

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

« Reply #1 - Posted 2009-04-20 08:05:23 »


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.



Offline forfor573

Junior Newbie

« Reply #2 - Posted 2009-04-20 08:48:22 »

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

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  Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline forfor573

Junior Newbie

« Reply #3 - Posted 2009-04-20 09:02:25 »

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  Smiley
Offline endolf

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

« Reply #4 - Posted 2009-04-20 12:33:07 »


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.



Offline forfor573

Junior Newbie

« Reply #5 - Posted 2009-04-20 17:04:39 »

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  Smiley
Offline endolf

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

« Reply #6 - Posted 2009-04-20 19:53:52 »

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


Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (10 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (28 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (25 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!