public void setInputControllerIndex(int index) { ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); net.java.games.input.Controller[] controllers = ce.getControllers(); if (controllers != null && index >= 0 && index < controllers.length) { setInputController(controllers[index]); } }
/** * Initialise the ControllIO instance * * @param i_parent */ private ControllIO(final PApplet i_parent) { environment = ControllerEnvironment.getEnvironment(); System.out.println(environment.getControllers().length); parent = i_parent; parent.registerDispose(this); parent.registerPre(this); setupDevices(); thread = new Thread(this); thread.start(); }
public static Controller getInstance() { if (instance == null) { // Disable JInput messages sent to stdout... java.util.logging.Logger.getLogger("net.java.games.input.DefaultControllerEnvironment") .setLevel(Level.WARNING); ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); net.java.games.input.Controller[] controllers = ce.getControllers(); net.java.games.input.Controller inputController = null; // Reuse the controller from the settings String controllerName = Settings.getInstance().readString("controller.controllerName"); // The controllerNameIndex is the index when several controllers have // the same name. 0 to use the first controller with the given name, // 1, to use the second... int controllerNameIndex = Settings.getInstance().readInt("controller.controllerNameIndex", 0); if (controllerName != null) { for (int i = 0; controllers != null && i < controllers.length; i++) { if (controllerName.equals(controllers[i].getName())) { inputController = controllers[i]; if (controllerNameIndex <= 0) { break; } controllerNameIndex--; } } } if (inputController == null) { // Use the first KEYBOARD controller for (int i = 0; controllers != null && i < controllers.length; i++) { if (isKeyboardController(controllers[i])) { inputController = controllers[i]; break; } } } if (inputController == null) { log.info(String.format("No KEYBOARD controller found")); for (int i = 0; controllers != null && i < controllers.length; i++) { log.info(String.format(" Controller: '%s'", controllers[i].getName())); } } else { log.info(String.format("Using default controller '%s'", inputController.getName())); } instance = new Controller(inputController); instance.init(); } return instance; }
private Controller getXboxController() { // Detect if we have an Xbox controller present System.out.println("Checking Controller Support...."); ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); Controller[] cs = ce.getControllers(); for (Controller c : cs) { if (c.getName().contains("XBOX 360")) { if (c.getType() == Controller.Type.GAMEPAD) { return c; } } } return null; }
/** * Save first founded controller of given type. * * @param controllerType Desired controller type. */ private void initController(Controller.Type controllerType_1, Controller.Type controllerType_2) { Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); for (int i = 0; i < controllers.length && controller == null; i++) { if (controllers[i].getType() == controllerType_1 || controllers[i].getType() == controllerType_2) { controller = controllers[i]; break; } } }
public boolean getDrums() { drumPort = -1; drumsAreConnected = false; ca = ControllerEnvironment.getDefaultEnvironment().getControllers(); for (int i = 0; i < ca.length; i++) { if (ca[i].poll() && ca[i].getName().equals("Harmonix Drum Kit for PlayStation(R)3")) { drumsAreConnected = true; drumPort = i; } } return drumsAreConnected; }
/** * Get a list of controllers connected to the computer * * @return All controllers linked to the computer */ public static ArrayList<Controller> getControllers() { ArrayList<Controller> foundControllers = new ArrayList<>(); Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); for (int i = 0; i < controllers.length; i++) { Controller controller = controllers[i]; if (controller.getType() == Controller.Type.STICK || controller.getType() == Controller.Type.GAMEPAD || controller.getType() == Controller.Type.WHEEL || controller.getType() == Controller.Type.FINGERSTICK) { // Add new controller to the list of all controllers. foundControllers.add(controller); } } return foundControllers; }
private void setController() { Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); for (int i = 0; i < controllers.length && controller == null; i++) { if (controllers[i].getType() == Controller.Type.STICK || controllers[i].getType() == Controller.Type.GAMEPAD) { this.controller = controllers[i]; } } if (controller == null) { throw new NoControllerFoundException(); } else { for (int i = 0; i < ComponentWrapper.componentWrappers.length; i++) { ComponentWrapper component = ComponentWrapper.componentWrappers[i]; if (component.getComponentNumber() < controller.getComponents().length) { component.setComponent(controller.getComponents()[component.getComponentNumber()]); } else { component.setComponent(controller.getComponents()[0]); System.err.println("Component number out of range please reconfigure your joystick!"); } } } }
/** Puts the available devices into the devices List */ private void setupDevices() { final Controller[] controllers = environment.getControllers(); for (int i = 0; i < controllers.length; i++) { devices.add(new ControllDevice(controllers[i], parent)); } }