I'm using JInput for Gamepad control on Win7 64bit. I ran into a problem: Once I get the DefaultEnvironment
the controller list doesn't get updated or refreshed.
for (Controller c : ControllerEnvironment.getDefaultEnvironment().getControllers()) {
if (c.getType() == Controller.Type.GAMEPAD) {
pluggedControllers.put(c);
}
}
So if a controller gets plugged in or out after i called ControllerEnvironment.getDefaultEnvironment()
nothing changes. The list will still provide a dead controller and new controllers can't be added.
Currently I'm using this workaround which is quite ugly I think. Any ideas how I can make it work with out this hack:
if (System.getProperty("os.name").equals("Windows 7") &&
System.getProperty("os.arch").equals("amd64"))
try {
Class<?> clazz = Class.forName("net.java.games.input.DefaultControllerEnvironment");
Constructor<?> defaultConstructor = clazz.getDeclaredConstructor();
defaultConstructor.setAccessible(true); // set visibility to public
Field defaultEnvironementField = ControllerEnvironment.class.getDeclaredField("defaultEnvironment");
defaultEnvironementField.setAccessible(true);
defaultEnvironementField.set(ControllerEnvironment.getDefaultEnvironment(), defaultConstructor.newInstance());
} catch (Exception e) {
e.printStackTrace();
}