net.java.games.input.Component Java Examples
The following examples show how to use
net.java.games.input.Component.
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: JogTrainerWidget.java From BowlerStudio with GNU General Public License v3.0 | 5 votes |
@Override public void onEvent(Component arg0, Event arg1, float value, String arg3) { if(Math.abs(value)>0.75 && selected!=null){ Platform.runLater(()->selected.setText(arg0.getName())); } }
Example #2
Source File: JInputJoyInput.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void loadIdentifiers(int controllerIdx, Controller c){ Component[] ces = c.getComponents(); int numButtons = 0; int numAxes = 0; xAxis = -1; yAxis = -1; for (Component comp : ces){ Identifier id = comp.getIdentifier(); if (id instanceof Button){ buttonIdsToIndices[controllerIdx].put((Button)id, numButtons); numButtons ++; }else if (id instanceof Axis){ Axis axis = (Axis) id; if (axis == Axis.X){ xAxis = numAxes; }else if (axis == Axis.Y){ yAxis = numAxes; } axisIdsToIndices[controllerIdx].put((Axis)id, numAxes); numAxes ++; } } }
Example #3
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 #4
Source File: ControllerImpl.java From halfnes with GNU General Public License v3.0 | 5 votes |
private boolean isPressed(Event event) { Component component = event.getComponent(); if (component.isAnalog()) { if (Math.abs(event.getValue()) > 0.2f) { return true; } else { return false; } } else if (event.getValue() == 0) { return false; } else { return true; } }
Example #5
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 #6
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 #7
Source File: JInputManager.java From nullpomino with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Check if specific key is down or not. * @param key SLICK keycode * @return true if the key is down */ public static boolean isKeyDown(int key) { if(keyboard != null) { Component.Identifier.Key jinputKey = keyMap.get(key); return keyboard.isKeyDown(jinputKey); } return false; }
Example #8
Source File: JogWidget.java From BowlerStudio with GNU General Public License v3.0 | 5 votes |
@Override public void onEvent(Component comp, net.java.games.input.Event event, float value, String eventString) { if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKiny", "y"))) x=value; if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKinz", "rz"))) y=value; if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKinx", "x"))) rz=-value; if(comp.getName().toLowerCase().contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogKinslider", "slider"))) slider=-value; if(Math.abs(x)<.01) x=0; if(Math.abs(y)<.01) y=0; if(Math.abs(rz)<.01) rz=0; if(Math.abs(slider)<.01) slider=0; if(x==0.0&&y==0.0 &&rz==0.0&&slider==0) { //System.out.println("Stoping on="+comp.getName()); stop=true; try { getKin().setDesiredTaskSpaceTransform(getKin().getCurrentTaskSpaceTransform(), 0); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }else stop=false; }
Example #9
Source File: LinkSliderWidget.java From BowlerStudio with GNU General Public License v3.0 | 5 votes |
@Override public void onEvent(Component comp, net.java.games.input.Event event, float value, String eventString) { if (comp.getName().toLowerCase() .contentEquals((String) ConfigurationDatabase.getObject(paramsKey, "jogLink", "x"))) slider = -value; if (Math.abs(slider) < .01) slider = 0; if (slider == 0) { // System.out.println("Stoping on="+comp.getName()); stop = true; } else stop = false; }
Example #10
Source File: Gadapter.java From zxpoly with GNU General Public License v3.0 | 4 votes |
@Override public void run() { try { while (!Thread.currentThread().isInterrupted() && this.controllerThread.get() != null) { if (!this.controller.poll()) { break; } float buttonAccum = 0.0f; boolean buttonDetected = false; for (final Component c : this.controller.getComponents()) { final Component.Identifier identifier = c.getIdentifier(); final float pollData = c.getPollData(); final boolean minusOne = Float.compare(pollData, -1.0f) == 0; final boolean plusOne = Float.compare(pollData, 1.0f) == 0; if (identifier == Component.Identifier.Axis.X) { if (minusOne) { doLeft(); } else if (plusOne) { doRight(); } else { doCenterX(); } } else if (identifier == Component.Identifier.Axis.Y) { if (minusOne) { this.doUp(); } else if (plusOne) { this.doDown(); } else { this.doCenterY(); } } else if (identifier instanceof Component.Identifier.Button) { buttonAccum += Math.abs(pollData); buttonDetected = true; } } if (buttonDetected) { this.doFire(buttonAccum != 0.0f); } try { Thread.sleep(10); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } finally { this.parent.notifyUnregisterGadapter(this); } }
Example #11
Source File: InputManager.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
static public void updateMouse(Controller controller) { //* Component[] components = controller.getComponents(); for(int j=0;j<components.length;j++){ Component c = components[j]; /*/ EventQueue queue = controller.getEventQueue(); Event event = new Event(); while(queue.getNextEvent(event)) { Component c = event.getComponent(); //*/ /* Log.message("\t"+c.getName()+ ":"+c.getIdentifier().getName()+ ":"+(c.isAnalog()?"Abs":"Rel")+ ":"+(c.isAnalog()?"Analog":"Digital")+ ":"+(c.getDeadZone())+ ":"+(c.getPollData()));//*/ if(c.isAnalog()) { double v = c.getPollData(); if(c.getIdentifier()==Identifier.Axis.X) setRawValue(Source.MOUSE_X,v); if(c.getIdentifier()==Identifier.Axis.Y) setRawValue(Source.MOUSE_Y,v); if(c.getIdentifier()==Identifier.Axis.Z) setRawValue(Source.MOUSE_Z,v); } else { // digital if(c.getPollData()==1) { if(c.getIdentifier()==Identifier.Button.LEFT ) setRawValue(Source.MOUSE_LEFT,1); if(c.getIdentifier()==Identifier.Button.MIDDLE) setRawValue(Source.MOUSE_MIDDLE,1); if(c.getIdentifier()==Identifier.Button.RIGHT ) setRawValue(Source.MOUSE_RIGHT,1); } } } }
Example #12
Source File: ControllerImpl.java From halfnes with GNU General Public License v3.0 | 4 votes |
public ControllerImpl(final java.awt.Component parent, final int controllernum) { this(controllernum); //this.parent = parent; parent.addKeyListener(this); }
Example #13
Source File: ControllerImpl.java From halfnes with GNU General Public License v3.0 | 4 votes |
private Runnable eventQueueLoop() { return new Runnable() { @Override public void run() { if (gameController != null) { Event event = new Event(); while (!Thread.interrupted()) { gameController.poll(); EventQueue queue = gameController.getEventQueue(); while (queue.getNextEvent(event)) { Component component = event.getComponent(); if (component.getIdentifier() == Component.Identifier.Axis.X) { if (event.getValue() > threshold) { gamepadbyte |= BIT7;//left on, right off gamepadbyte &= ~BIT6; } else if (event.getValue() < -threshold) { gamepadbyte |= BIT6; gamepadbyte &= ~BIT7; } else { gamepadbyte &= ~(BIT7 | BIT6); } } else if (component.getIdentifier() == Component.Identifier.Axis.Y) { if (event.getValue() > threshold) { gamepadbyte |= BIT5;//up on, down off gamepadbyte &= ~BIT4; } else if (event.getValue() < -threshold) { gamepadbyte |= BIT4;//down on, up off gamepadbyte &= ~BIT5; } else { gamepadbyte &= ~(BIT4 | BIT5); } } else if (component == buttons[0]) { if (isPressed(event)) { gamepadbyte |= BIT0; } else { gamepadbyte &= ~BIT0; } } else if (component == buttons[1]) { if (isPressed(event)) { gamepadbyte |= BIT1; } else { gamepadbyte &= ~BIT1; } } else if (component == buttons[2]) { if (isPressed(event)) { gamepadbyte |= BIT2; } else { gamepadbyte &= ~BIT2; } } else if (component == buttons[3]) { if (isPressed(event)) { gamepadbyte |= BIT3; } else { gamepadbyte &= ~BIT3; } } } try { Thread.sleep(5); } catch (InterruptedException e) { // Preserve interrupt status Thread.currentThread().interrupt(); } } } } }; }
Example #14
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 #15
Source File: ControllerImpl.java From halfnes with GNU General Public License v3.0 | 4 votes |
/** * Return the available buttons on this controller (by priority order). */ private static Component[] getButtons(Controller controller) { List<Component> buttons = new ArrayList<>(); // Get this controllers components (buttons and axis) Component[] components = controller.getComponents(); for (Component component : components) { if (component.getIdentifier() instanceof Component.Identifier.Button) { buttons.add(component); } } return buttons.toArray(new Component[0]); }
Example #16
Source File: InputManager.java From Robot-Overlord-App with GNU General Public License v2.0 | 2 votes |
static public void updateKeyboard(Controller controller) { //* Component[] components = controller.getComponents(); for(int j=0;j<components.length;j++){ Component c = components[j]; /*/ EventQueue queue = controller.getEventQueue(); Event event = new Event(); while(queue.getNextEvent(event)) { Component c = event.getComponent(); //*/ /* Log.message("\t"+c.getName()+ ":"+c.getIdentifier().getName()+ ":"+(c.isAnalog()?"Abs":"Rel")+ ":"+(c.isAnalog()?"Analog":"Digital")+ ":"+(c.getDeadZone())+ ":"+(c.getPollData()));//*/ if(!c.isAnalog()) { // digital if(c.getPollData()==1) { //Log.message(c.getIdentifier().getName()); if(c.getIdentifier()==Identifier.Key.DELETE ) setRawValue(Source.KEY_DELETE,1); if(c.getIdentifier()==Identifier.Key.RETURN ) setRawValue(Source.KEY_RETURN,1); if(c.getIdentifier()==Identifier.Key.LSHIFT ) setRawValue(Source.KEY_LSHIFT,1); if(c.getIdentifier()==Identifier.Key.RSHIFT ) setRawValue(Source.KEY_RSHIFT,1); if(c.getIdentifier()==Identifier.Key.RALT ) setRawValue(Source.KEY_RALT,1); if(c.getIdentifier()==Identifier.Key.LALT ) setRawValue(Source.KEY_LALT,1); if(c.getIdentifier()==Identifier.Key.RCONTROL) setRawValue(Source.KEY_RCONTROL,1); if(c.getIdentifier()==Identifier.Key.LCONTROL) setRawValue(Source.KEY_LCONTROL,1); if(c.getIdentifier()==Identifier.Key.BACK ) setRawValue(Source.KEY_BACKSPACE,1); if(c.getIdentifier()==Identifier.Key.Q ) setRawValue(Source.KEY_Q,1); if(c.getIdentifier()==Identifier.Key.E ) setRawValue(Source.KEY_E,1); if(c.getIdentifier()==Identifier.Key.W ) setRawValue(Source.KEY_W,1); if(c.getIdentifier()==Identifier.Key.A ) setRawValue(Source.KEY_A,1); if(c.getIdentifier()==Identifier.Key.S ) setRawValue(Source.KEY_S,1); if(c.getIdentifier()==Identifier.Key.D ) setRawValue(Source.KEY_D,1); if(c.getIdentifier()==Identifier.Key.NUMPADENTER) setRawValue(Source.KEY_ENTER,1); if(c.getIdentifier()==Identifier.Key.TAB) setRawValue(Source.KEY_TAB,1); if(c.getIdentifier()==Identifier.Key._0) setRawValue(Source.KEY_0,1); if(c.getIdentifier()==Identifier.Key._1) setRawValue(Source.KEY_1,1); if(c.getIdentifier()==Identifier.Key._2) setRawValue(Source.KEY_2,1); if(c.getIdentifier()==Identifier.Key._3) setRawValue(Source.KEY_3,1); if(c.getIdentifier()==Identifier.Key._4) setRawValue(Source.KEY_4,1); if(c.getIdentifier()==Identifier.Key._5) setRawValue(Source.KEY_5,1); if(c.getIdentifier()==Identifier.Key._6) setRawValue(Source.KEY_6,1); if(c.getIdentifier()==Identifier.Key._7) setRawValue(Source.KEY_7,1); if(c.getIdentifier()==Identifier.Key._8) setRawValue(Source.KEY_8,1); if(c.getIdentifier()==Identifier.Key._9) setRawValue(Source.KEY_9,1); if(c.getIdentifier()==Identifier.Key.ESCAPE) setRawValue(Source.KEY_ESCAPE,1); if(c.getIdentifier()==Identifier.Key.SLASH) setRawValue(Source.KEY_FRONTSLASH,1); if(c.getIdentifier()==Identifier.Key.BACKSLASH) setRawValue(Source.KEY_BACKSLASH,1); if(c.getIdentifier()==Identifier.Key.EQUALS) setRawValue(Source.KEY_PLUS,1); if(c.getIdentifier()==Identifier.Key.ADD) setRawValue(Source.KEY_PLUS,1); if(c.getIdentifier()==Identifier.Key.COMMA) setRawValue(Source.KEY_LESSTHAN,1); if(c.getIdentifier()==Identifier.Key.PERIOD) setRawValue(Source.KEY_GREATERTHAN,1); if(c.getIdentifier()==Identifier.Key.SPACE) setRawValue(Source.KEY_SPACE,1); if(c.getIdentifier()==Identifier.Key.GRAVE) setRawValue(Source.KEY_TILDE,1); if(c.getIdentifier()==Identifier.Key.F1) setRawValue(Source.KEY_F1,1); if(c.getIdentifier()==Identifier.Key.F2) setRawValue(Source.KEY_F2,1); if(c.getIdentifier()==Identifier.Key.F3) setRawValue(Source.KEY_F3,1); if(c.getIdentifier()==Identifier.Key.F4) setRawValue(Source.KEY_F4,1); if(c.getIdentifier()==Identifier.Key.F5) setRawValue(Source.KEY_F5,1); if(c.getIdentifier()==Identifier.Key.F6) setRawValue(Source.KEY_F6,1); if(c.getIdentifier()==Identifier.Key.F7) setRawValue(Source.KEY_F7,1); if(c.getIdentifier()==Identifier.Key.F8) setRawValue(Source.KEY_F8,1); if(c.getIdentifier()==Identifier.Key.F9) setRawValue(Source.KEY_F9,1); if(c.getIdentifier()==Identifier.Key.F10) setRawValue(Source.KEY_F10,1); if(c.getIdentifier()==Identifier.Key.F11) setRawValue(Source.KEY_F11,1); if(c.getIdentifier()==Identifier.Key.F12) setRawValue(Source.KEY_F12,1); } } } }
Example #17
Source File: JInputManager.java From nullpomino with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Convert Slick's keycode to JInput's key identifier. * @param key Slick's keycode * @return JInput's key identifier */ public static Component.Identifier.Key slickToJInputKey(int key) { return keyMap.get(key); }
Example #18
Source File: InputManager.java From Robot-Overlord-App with GNU General Public License v2.0 | 1 votes |
static public void updateStick(Controller controller) { //* Component[] components = controller.getComponents(); for(int j=0;j<components.length;j++){ Component c = components[j]; /*/ EventQueue queue = controller.getEventQueue(); Event event = new Event(); while(queue.getNextEvent(event)) { Component c = event.getComponent(); //*/ /* Log.message("\t"+c.getName()+ ":"+c.getIdentifier().getName()+ ":"+(c.isAnalog()?"Abs":"Rel")+ ":"+(c.isAnalog()?"Analog":"Digital")+ ":"+(c.getDeadZone())+ ":"+(c.getPollData()));//*/ if(c.isAnalog()) { double v = c.getPollData(); final double DEADZONE=0.1; double deadzone = DEADZONE; // c.getDeadZone() is very small? if(v> deadzone) v=(v-deadzone)/(1.0-deadzone); // scale 0....1 else if(v<-deadzone) v=(v+deadzone)/(1.0-deadzone); // scale 0...-1 else continue; // inside dead zone, ignore. if(c.getIdentifier()==Identifier.Axis.Z ) setRawValue(Source.STICK_RX,v); // right analog stick, + is right -1 is left if(c.getIdentifier()==Identifier.Axis.RZ) setRawValue(Source.STICK_RY,v); // right analog stick, + is down -1 is up if(c.getIdentifier()==Identifier.Axis.RY) setRawValue(Source.STICK_R2,v); // R2, +1 is pressed -1 is unpressed if(c.getIdentifier()==Identifier.Axis.RX) setRawValue(Source.STICK_L2,v); // L2, +1 is pressed -1 is unpressed if(c.getIdentifier()==Identifier.Axis.X ) setRawValue(Source.STICK_LX,v); // left analog stick, +1 is right -1 is left if(c.getIdentifier()==Identifier.Axis.Y ) setRawValue(Source.STICK_LY,v); // left analog stick, -1 is up +1 is down } else { // digital if(c.getPollData()==1) { if(c.getIdentifier()==Identifier.Button._0 ) setRawValue(Source.STICK_SQUARE,1); // square if(c.getIdentifier()==Identifier.Button._1 ) setRawValue(Source.STICK_X,1); // x if(c.getIdentifier()==Identifier.Button._2 ) setRawValue(Source.STICK_CIRCLE,1); // circle if(c.getIdentifier()==Identifier.Button._3 ) setRawValue(Source.STICK_TRIANGLE,1); // triangle if(c.getIdentifier()==Identifier.Button._4 ) setRawValue(Source.STICK_L1,1); // L1? if(c.getIdentifier()==Identifier.Button._5 ) setRawValue(Source.STICK_R1,1); // R1? if(c.getIdentifier()==Identifier.Button._8 ) setRawValue(Source.STICK_SHARE,1); // share button if(c.getIdentifier()==Identifier.Button._9 ) setRawValue(Source.STICK_OPTIONS,1); // option button if(c.getIdentifier()==Identifier.Button._13) setRawValue(Source.STICK_TOUCHPAD,1); // touch pad } if(c.getIdentifier()==Identifier.Axis.POV) { // D-pad buttons float pollData = c.getPollData(); if(pollData == Component.POV.DOWN ) setRawValue(Source.STICK_DPADY,-1); else if(pollData == Component.POV.UP ) setRawValue(Source.STICK_DPADY,1); else if(pollData == Component.POV.LEFT ) setRawValue(Source.STICK_DPADX,-1); else if(pollData == Component.POV.RIGHT) setRawValue(Source.STICK_DPADX,1); } } } }