JInput Controller connect disconnect problem SOVLED!!!

Greetings fellow developers. I have been searching this topic only to find that one has succeeded and failed to provide their results because they like proprietary bullshit.

I have been looking to make a push to talk handset for a project I am doing with the United States Air Force. I found it necessary that I must be able to find a device that I plug/unplug during the program running.
"
I come to find that the immediate issue was that “ControllerEnvironment.getDefaultEnvironment().getControllers()” never changed the list of Controllers while the program is running. So why is that?

Well lets start with the the call “ControllerEnvironment.getDefaultEnvironment().getControllers()”. This class does not have a protected Constructor. so in order to have access to the constructor you have to be part of the package it is contained in. This is not practical. So I made this public, but only to find that I still could not call construction on it. so I undid that.

The next thing I notice is the getDefaultEnvironment(). Ths actually uses a constructor. Once again, this is protected. So I made it public.

Next, for testing purpose I programmed a button like so in my GUI;

if(e.getSource().equals(button1))
{
ce = new DefaultControllerEnviornment();

    Controller[] controller = ce.getControllers();
    
    for(int i = 0; i < controller.length; i++)
    {
             System.out.println(controller[i].getName());
     }

}

every time i press this button, it reconstructs the list of controllers and prints them out.

so i removed and added devices while pressing this button. Viola!! it worked, the list was updating the devices.

so for the next part you basically want to created a TimerTask that runs this code every so often to update the list. How often is up to the use of your software and how important an updated list of controllers is.

I have yet to test how this effects the rest of my code polling the controllers, but this is a start, and it is far easier than try to understand and edit the native code.

I hope this helps all of you out, i have spent a couple weeks researching this, and I solved it in a matter of half an hour just mucking through the code.

You probably need to make sure that when the new device list is evaluated, all the old handles are removed to the old devices in the native code, otherwise you might find you run out of file handles under unix systems. I don’t know how this handles opening devices in exclusive mode on windows either?

but other than that, it seems like a reasonable work around. Under unix this would be the way to do it anyways, under windows there is a listener interface for the directx bindings IIRC, but that’s for a more permanent solution, if anyone fancies the task :slight_smile:

Endolf

by doing it this way your are recalling the native calls, that build the list of devices in java. there was no other way to update the list than to call the native code again, but there was no given method to do that.

This reminds me, I should put a non-military only clause on my OSS licenses…

problem sovled? someone in the military should be able to spell better.

in the latest build you can create an instance of DirectAndRawInputEnvironmentPlugin every time you want to know what is plugged in. then use the getControllers() method and so on.