net.java.games.input.ControllerEnvironment Java Examples
The following examples show how to use
net.java.games.input.ControllerEnvironment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JInputManager.java From nullpomino with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Init */ public static void initKeyboard() { controllerEnvironment = ControllerEnvironment.getDefaultEnvironment(); controllers = controllerEnvironment.getControllers(); for(int i = 0; i < controllers.length; i++) { Controller c = controllers[i]; if((c.getType() == Controller.Type.KEYBOARD) && (c instanceof Keyboard)) { if(NullpoMinoSlick.useJInputKeyboard) { log.debug("initKeyboard: Keyboard found"); } keyboard = (Keyboard)c; } } if((keyboard == null) && (NullpoMinoSlick.useJInputKeyboard)) { log.error("initKeyboard: Keyboard NOT FOUND"); // Linux if(System.getProperty("os.name").startsWith("Linux")) { log.error("If you can use sudo, try the following command and start NullpoMino again:"); log.error("sudo chmod go+r /dev/input/*"); } } }
Example #2
Source File: InputManager.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
/** * output all controllers, their components, and some details about those components. */ static public void listAllControllers() { ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); Log.message("supported="+ce.isSupported()); Controller[] ca = ce.getControllers(); for(int i =0;i<ca.length;i++){ Component[] components = ca[i].getComponents(); Log.message("Controller "+i+":"+ca[i].getName()+" "+ca[i].getType().toString()); Log.message("Component Count: "+components.length); // Get this controllers components (buttons and axis) for(int j=0;j<components.length;j++){ Log.message("\t"+j+": "+components[j].getName() + " " + components[j].getIdentifier().getName() +" (" + (components[j].isRelative() ? "Relative" : "Absolute") + " " + (components[j].isAnalog()? "Analog" : "Digital") + ")"); } } }
Example #3
Source File: JInputTest.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
/** * Figure out which input just changed. Requires human input. */ //@Test public void detectSingleInputChangeB() { int i,j; while(true) { // get the latest state InputManager.update(true); Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers(); for(i=0;i<ca.length;i++) { Component[] components = ca[i].getComponents(); for(j=0;j<components.length;j++) { float diff = components[j].getPollData(); if(diff>0.5) { // change to state System.out.println("Found "+ca[i].getName()+"."+components[j].getName()+"="+diff); //return; } } } } }
Example #4
Source File: GamepadListener.java From haxademic with MIT License | 5 votes |
public GamepadListener() { new Thread(new Runnable() { public void run() { // look for controllers via JInput Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); if (controllers.length == 0) { P.error("JInput Found no controllers."); } else { P.out("Gamepads found:"); for (int i = 0; i < controllers.length; i++) { P.out("["+i+"] " + controllers[i].getName(), " | ", controllers[i].getType()); } } while (true) { // poll each device for (int i = 0; i < controllers.length; i++) { // On OS X, Gamepad showed up as GAMEPAD, and on Windows, UNKNOWN if(controllers[i].getType() != Controller.Type.MOUSE && controllers[i].getType() != Controller.Type.KEYBOARD) { // get input updates controllers[i].poll(); EventQueue queue = controllers[i].getEventQueue(); Event event = new Event(); while (queue.getNextEvent(event)) { Component comp = event.getComponent(); float value = event.getValue(); GamepadState.instance().setControlValue(comp.getName(), value); } } } } }}).start(); }
Example #5
Source File: InputManager.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
static public void update(boolean isMouseIn) { Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers(); advanceKeyStates(); int numMice=0; //int numSticks=0; //int numKeyboard=0; for(int i=0;i<ca.length;i++){ // poll all controllers once per frame if(!ca[i].poll()) { // TODO poll failed, device disconnected? return; } //Log.message(ca[i].getType()); if(ca[i].getType()==Controller.Type.MOUSE) { if(numMice==0) { if(isMouseIn) updateMouse(ca[i]); } ++numMice; } else if(ca[i].getType()==Controller.Type.STICK) { //if(numSticks==0) { updateStick(ca[i]); //} //++numSticks; } else if(ca[i].getType()==Controller.Type.KEYBOARD) { //if(numKeyboard==0) { updateKeyboard(ca[i]); //} //++numKeyboard; } } //Log.message(numSticks+"/"+numMice+"/"+numKeyboard); }
Example #6
Source File: ControllerImpl.java From halfnes with GNU General Public License v3.0 | 4 votes |
/** * This method detects the available joysticks / gamepads on the computer * and return them in a list. * * @return List of available joysticks / gamepads connected to the computer */ private static Controller[] getAvailablePadControllers() { List<Controller> gameControllers = new ArrayList<>(); // Get a list of the controllers JInput knows about and can interact // with Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); // Check the useable controllers (gamepads or joysticks with at least 2 // axis and 2 buttons) for (Controller controller : controllers) { if ((controller.getType() == Controller.Type.GAMEPAD) || (controller.getType() == Controller.Type.STICK)) { int nbOfAxis = 0; // Get this controllers components (buttons and axis) Component[] components = controller.getComponents(); // Check the availability of X/Y axis and at least 2 buttons // (for A and B, because select and start can use the keyboard) for (Component component : components) { if ((component.getIdentifier() == Component.Identifier.Axis.X) || (component.getIdentifier() == Component.Identifier.Axis.Y)) { nbOfAxis++; } } if ((nbOfAxis >= 2) && (getButtons(controller).length >= 2)) { // Valid game controller gameControllers.add(controller); } } } return gameControllers.toArray(new Controller[0]); }
Example #7
Source File: JInputTest.java From halfnes with GNU General Public License v3.0 | 4 votes |
@Test public void testJInput() { ControllerEnvironment controllerEnvironment = ControllerEnvironment.getDefaultEnvironment(); Controller[] controllers = controllerEnvironment.getControllers(); System.out.println(String.format("%s controllers found.", controllers.length)); Arrays.asList(controllers).forEach(controller -> { System.out.println(String.format(" %s (%s)", controller, controller.getType())); }); }