Search in sources :

Example 1 with Component

use of net.java.games.input.Component in project lwjgl by LWJGL.

the class LWJGLKeyboard method getNextDeviceEvent.

protected synchronized boolean getNextDeviceEvent(Event event) throws IOException {
    if (!org.lwjgl.input.Keyboard.isCreated())
        return false;
    if (!org.lwjgl.input.Keyboard.next())
        return false;
    int lwjgl_key = org.lwjgl.input.Keyboard.getEventKey();
    if (lwjgl_key == org.lwjgl.input.Keyboard.KEY_NONE)
        return false;
    Component.Identifier.Key key_id = KeyMap.map(lwjgl_key);
    if (key_id == null)
        return false;
    Component key = getComponent(key_id);
    if (key == null)
        return false;
    float value = org.lwjgl.input.Keyboard.getEventKeyState() ? 1 : 0;
    event.set(key, value, org.lwjgl.input.Keyboard.getEventNanoseconds());
    return true;
}
Also used : Component(net.java.games.input.Component) AbstractComponent(net.java.games.input.AbstractComponent)

Example 2 with Component

use of net.java.games.input.Component in project JMRI by JMRI.

the class TreeModel method loadSystem.

/**
     * @return true for success
     */
boolean loadSystem() {
    // Get a list of the controllers JInput knows about and can interact with
    log.debug("start looking for controllers");
    try {
        ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
        log.debug("Found " + ca.length + " controllers");
    } catch (Exception ex) {
        // this is probably ClassNotFoundException, but that's not part of the interface
        // could not load some component(s)
        log.debug("Found no controllers, handled Exception", ex);
        ca = null;
        return false;
    }
    for (int i = 0; i < ca.length; i++) {
        // Get this controllers components (buttons and axis)
        Component[] components = ca[i].getComponents();
        log.info("Controller " + ca[i].getName() + " has " + components.length + " components");
        for (int j = 0; j < components.length; j++) {
            Controller controller = ca[i];
            Component component = components[j];
            // ensure controller node exists directly under root
            String cname = controller.getName() + " [" + controller.getType().toString() + "]";
            UsbNode cNode = UsbNode.getNode(cname, controller, null);
            cNode = (UsbNode) insertNode(cNode, dRoot);
            // Device (component) node
            String dname = component.getName() + " [" + component.getIdentifier().toString() + "]";
            UsbNode dNode = UsbNode.getNode(dname, controller, component);
            dNode = (UsbNode) insertNode(dNode, cNode);
            dNode.setValue(0.0f);
        }
    }
    return true;
}
Also used : Component(net.java.games.input.Component) Controller(net.java.games.input.Controller)

Example 3 with Component

use of net.java.games.input.Component in project Terasology by MovingBlocks.

the class JInputControllerDevice method convertEvent.

private ControllerAction convertEvent(Controller c, Event event) {
    Component comp = event.getComponent();
    Identifier id = comp.getIdentifier();
    float axisValue = comp.getPollData();
    Input input;
    ButtonState state = ButtonState.UP;
    if (id instanceof Identifier.Button) {
        state = event.getValue() != 0 ? ButtonState.DOWN : ButtonState.UP;
        Integer buttonId = buttonMap.get(id);
        if (buttonId == null) {
            // button not registered
            return null;
        }
        input = InputType.CONTROLLER_BUTTON.getInput(buttonId);
    } else if (id instanceof Identifier.Axis) {
        ControllerInfo info = config.getController(c.getName());
        if (id.equals(Identifier.Axis.X)) {
            if (Math.abs(axisValue) < info.getMovementDeadZone()) {
                axisValue = 0;
            }
            input = InputType.CONTROLLER_AXIS.getInput(ControllerId.X_AXIS);
        } else if (id.equals(Identifier.Axis.Y)) {
            if (Math.abs(axisValue) < info.getMovementDeadZone()) {
                axisValue = 0;
            }
            input = InputType.CONTROLLER_AXIS.getInput(ControllerId.Y_AXIS);
        } else if (id.equals(Identifier.Axis.Z)) {
            if (Math.abs(axisValue) < info.getMovementDeadZone()) {
                axisValue = 0;
            }
            input = InputType.CONTROLLER_AXIS.getInput(ControllerId.Z_AXIS);
        } else if (id.equals(Identifier.Axis.RX)) {
            if (Math.abs(axisValue) < info.getRotationDeadZone()) {
                axisValue = 0;
            }
            input = InputType.CONTROLLER_AXIS.getInput(ControllerId.RX_AXIS);
        } else if (id.equals(Identifier.Axis.RY)) {
            if (Math.abs(axisValue) < info.getRotationDeadZone()) {
                axisValue = 0;
            }
            input = InputType.CONTROLLER_AXIS.getInput(ControllerId.RY_AXIS);
        } else if (id.equals(Identifier.Axis.POV)) {
            // the poll data float value is actually an ID in this case
            boolean isX = (axisValue == Component.POV.LEFT) || (axisValue == Component.POV.RIGHT);
            boolean isY = (axisValue == Component.POV.UP) || (axisValue == Component.POV.DOWN);
            if (isX || isY) {
                input = InputType.CONTROLLER_AXIS.getInput(isX ? ControllerId.POVX_AXIS : ControllerId.POVY_AXIS);
                if ((axisValue == Component.POV.UP) || (axisValue == Component.POV.LEFT)) {
                    axisValue = -1;
                }
                if ((axisValue == Component.POV.DOWN) || (axisValue == Component.POV.RIGHT)) {
                    axisValue = 1;
                }
            } else {
                // TODO: handle 8-button POVs
                return null;
            }
        } else {
            // unrecognized axis
            return null;
        }
    } else {
        // unrecognized id (e.g. Identifier.Key)
        return null;
    }
    return new ControllerAction(input, c.getName(), state, axisValue);
}
Also used : Input(org.terasology.input.Input) Identifier(net.java.games.input.Component.Identifier) Button(net.java.games.input.Component.Identifier.Button) Component(net.java.games.input.Component) ButtonState(org.terasology.input.ButtonState) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo) ControllerAction(org.terasology.input.device.ControllerAction)

Example 4 with Component

use of net.java.games.input.Component in project litiengine by gurkenlabs.

the class Gamepad method update.

@Override
public void update() {
    final boolean couldPoll = this.controller.poll();
    if (!couldPoll) {
        this.dispose();
    }
    final Event event = new Event();
    while (this.controller.getEventQueue().getNextEvent(event)) {
        this.handlePollEvents(event);
    }
    for (Component comp : this.controller.getComponents()) {
        if (Math.abs(comp.getPollData()) > getDeadZone(comp.getIdentifier())) {
            this.handlePressed(comp);
        } else {
            this.handleRelease(comp);
        }
    }
}
Also used : Event(net.java.games.input.Event) Component(net.java.games.input.Component)

Example 5 with Component

use of net.java.games.input.Component in project j6dof-flight-sim by chris-ali.

the class JoystickVisitor method handleDeviceInput.

@Override
public void handleDeviceInput(Controller device) {
    if (!canHandleDevice(device))
        return;
    JoystickAssignments assignments = joystickAssignments.get(device.getName());
    Map<String, JoystickAxis> axisAssignments = assignments.getAxisAssignments();
    Map<String, KeyCommand> buttonAssignments = assignments.getButtonAssignments();
    Map<Float, KeyCommand> hatAssignments = assignments.getHatAssignments();
    if (device.poll()) {
        Event event = new Event();
        while (device.getEventQueue().getNextEvent(event)) {
            Component component = event.getComponent();
            Identifier componentIdentifier = component.getIdentifier();
            String componentName = componentIdentifier.getName();
            float pollValue = component.getPollData();
            // Buttons
            if (buttonAssignments != null && componentIdentifier.getName().matches("^[0-9]*$")) {
                // If the component name contains only numbers, it is a button
                KeyCommand command = buttonAssignments.get(componentName);
                if (command != null)
                    actuator.handleParameterChange(command, pollValue);
                continue;
            }
            // Hat Switch
            if (hatAssignments != null && componentIdentifier == Axis.POV) {
                KeyCommand command = hatAssignments.get(pollValue);
                if (command != null)
                    actuator.handleParameterChange(command, pollValue);
                continue;
            }
            // Joystick Axes
            if (axisAssignments != null) {
                JoystickAxis axis = axisAssignments.get(componentName);
                if (axis != null)
                    actuator.handleParameterChange(axis.getAxisAssignment(), pollValue);
                continue;
            }
        }
    }
}
Also used : Identifier(net.java.games.input.Component.Identifier) Event(net.java.games.input.Event) JoystickAssignments(com.chrisali.javaflightsim.simulation.setup.ControlsConfiguration.JoystickAssignments) JoystickAxis(com.chrisali.javaflightsim.simulation.setup.JoystickAxis) KeyCommand(com.chrisali.javaflightsim.simulation.setup.KeyCommand) Component(net.java.games.input.Component)

Aggregations

Component (net.java.games.input.Component)9 Identifier (net.java.games.input.Component.Identifier)3 Event (net.java.games.input.Event)3 KeyCommand (com.chrisali.javaflightsim.simulation.setup.KeyCommand)2 AbstractComponent (net.java.games.input.AbstractComponent)2 JoystickAssignments (com.chrisali.javaflightsim.simulation.setup.ControlsConfiguration.JoystickAssignments)1 JoystickAxis (com.chrisali.javaflightsim.simulation.setup.JoystickAxis)1 Button (net.java.games.input.Component.Identifier.Button)1 Controller (net.java.games.input.Controller)1 EventQueue (net.java.games.input.EventQueue)1 ControllerInfo (org.terasology.config.ControllerConfig.ControllerInfo)1 ButtonState (org.terasology.input.ButtonState)1 Input (org.terasology.input.Input)1 ControllerAction (org.terasology.input.device.ControllerAction)1