net.java.games.input.Event Java Examples

The following examples show how to use net.java.games.input.Event. 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: LinkSliderWidget.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
@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 #2
Source File: JogTrainerWidget.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
@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 #3
Source File: ControllerImpl.java    From halfnes with GNU General Public License v3.0 5 votes vote down vote up
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 #4
Source File: GamepadListener.java    From haxademic with MIT License 5 votes vote down vote up
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: ControllerImpl.java    From halfnes with GNU General Public License v3.0 4 votes vote down vote up
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();
                    }
                }
            }
        }
    };
}