Java Code Examples for javafx.scene.input.KeyEvent#KEY_PRESSED

The following examples show how to use javafx.scene.input.KeyEvent#KEY_PRESSED . 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: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUpArrowKeyMoveTarget() {
	double oldX = pepperPopper.getPosition().getX();
	double oldY = pepperPopper.getPosition().getY();

	KeyEvent upArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "up", "up",
			KeyCode.UP, false, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), upArrowEvent);

	assertEquals(oldX, pepperPopper.getPosition().getX(), .001);
	assertEquals(oldY - TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getY(), .001);
}
 
Example 2
Source File: CameraController.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
private void handleKeyEvent(KeyEvent t) {
    if (t.getEventType() == KeyEvent.KEY_PRESSED) {
        handleKeyEvent(t, true);
    } else if (t.getEventType() == KeyEvent.KEY_RELEASED) {
        handleKeyEvent(t, true);
    }
    speed = getSpeedModifier(t);
}
 
Example 3
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDownArrowKeyProportionalResizeTarget() {
	double oldWidth = pepperPopper.getDimension().getWidth();
	double oldHeight = pepperPopper.getDimension().getHeight();

	KeyEvent downArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "down",
			"down", KeyCode.DOWN, true, true, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), downArrowEvent);

	assertEquals(oldWidth - (TargetView.SCALE_DELTA * (oldWidth / oldHeight)), pepperPopper.getDimension().getWidth(), .001);
	assertEquals(oldHeight - TargetView.SCALE_DELTA, pepperPopper.getDimension().getHeight(), .001);
}
 
Example 4
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUpArrowKeyProportionalResizeTarget() {
	double oldWidth = pepperPopper.getDimension().getWidth();
	double oldHeight = pepperPopper.getDimension().getHeight();

	KeyEvent upArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "up", "up",
			KeyCode.UP, true, true, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), upArrowEvent);

	assertEquals(oldWidth + (TargetView.SCALE_DELTA * (oldWidth / oldHeight)), pepperPopper.getDimension().getWidth(), .001);
	assertEquals(oldHeight + TargetView.SCALE_DELTA, pepperPopper.getDimension().getHeight(), .001);
}
 
Example 5
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDownArrowKeyResizeTarget() {
	double oldWidth = pepperPopper.getDimension().getWidth();
	double oldHeight = pepperPopper.getDimension().getHeight();

	KeyEvent downArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "down",
			"down", KeyCode.DOWN, true, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), downArrowEvent);

	assertEquals(oldWidth, pepperPopper.getDimension().getWidth(), .001);
	assertEquals(oldHeight - TargetView.SCALE_DELTA, pepperPopper.getDimension().getHeight(), .001);
}
 
Example 6
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUpArrowKeyResizeTarget() {
	double oldWidth = pepperPopper.getDimension().getWidth();
	double oldHeight = pepperPopper.getDimension().getHeight();

	KeyEvent upArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "up", "up",
			KeyCode.UP, true, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), upArrowEvent);

	assertEquals(oldWidth, pepperPopper.getDimension().getWidth(), .001);
	assertEquals(oldHeight + TargetView.SCALE_DELTA, pepperPopper.getDimension().getHeight(), .001);
}
 
Example 7
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testRightArrowKeyResizeTarget() {
	double oldWidth = pepperPopper.getDimension().getWidth();
	double oldHeight = pepperPopper.getDimension().getHeight();

	KeyEvent rightArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "right",
			"right", KeyCode.RIGHT, true, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), rightArrowEvent);

	assertEquals(oldWidth - TargetView.SCALE_DELTA, pepperPopper.getDimension().getWidth(), .001);
	assertEquals(oldHeight, pepperPopper.getDimension().getHeight(), .001);
}
 
Example 8
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLeftArrowKeyResizeTarget() {
	double oldWidth = pepperPopper.getDimension().getWidth();
	double oldHeight = pepperPopper.getDimension().getHeight();

	KeyEvent leftArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "left",
			"left", KeyCode.LEFT, true, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), leftArrowEvent);

	assertEquals(oldWidth + TargetView.SCALE_DELTA, pepperPopper.getDimension().getWidth(), .001);
	assertEquals(oldHeight, pepperPopper.getDimension().getHeight(), .001);
}
 
Example 9
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDownArrowKeyMoveTarget() {
	double oldX = pepperPopper.getPosition().getX();
	double oldY = pepperPopper.getPosition().getY();

	KeyEvent downArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "down",
			"down", KeyCode.DOWN, false, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), downArrowEvent);

	assertEquals(oldX, pepperPopper.getPosition().getX(), .001);
	assertEquals(oldY + TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getY(), .001);
}
 
Example 10
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testRightArrowKeyMoveTarget() {
	double oldX = pepperPopper.getPosition().getX();
	double oldY = pepperPopper.getPosition().getY();

	KeyEvent rightArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "right",
			"right", KeyCode.RIGHT, false, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), rightArrowEvent);

	assertEquals(oldX + TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getX(), .001);
	assertEquals(oldY, pepperPopper.getPosition().getY(), .001);
}
 
Example 11
Source File: TestTarget.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLeftArrowKeyMoveTarget() {
	double oldX = pepperPopper.getPosition().getX();
	double oldY = pepperPopper.getPosition().getY();

	KeyEvent leftArrowEvent = new KeyEvent(null, pepperPopper.getTargetGroup(), KeyEvent.KEY_PRESSED, "left",
			"left", KeyCode.LEFT, false, false, false, false);
	Event.fireEvent(pepperPopper.getTargetGroup(), leftArrowEvent);

	assertEquals(oldX - TargetView.MOVEMENT_DELTA, pepperPopper.getPosition().getX(), .001);
	assertEquals(oldY, pepperPopper.getPosition().getY(), .001);
}
 
Example 12
Source File: Keyboard.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
public EventHandler<KeyEvent> getListener() {
    return (KeyEvent event) -> {
        if (event.getEventType() == KeyEvent.KEY_PRESSED) {
            keyPressed(event);
        } else if (event.getEventType() == KeyEvent.KEY_RELEASED) {
            keyReleased(event);
        }
    };
}
 
Example 13
Source File: EventQueueDeviceTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private static void addToList(KeyEvent e) {
    final StringBuilder sb = new StringBuilder();
    if (e.getEventType() == KeyEvent.KEY_PRESSED) {
        sb.append(checkModifier(e) + " pressed " + e.getCode());
    }
    if (e.getEventType() == KeyEvent.KEY_RELEASED) {
        sb.append(checkModifier(e) + " released " + e.getCode());
    }
    kss.add(sb.toString().trim());
}
 
Example 14
Source File: CheckedValueFieldTests.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private KeyEvent getKeyEvent(final KeyCode keyCode) {
    return new KeyEvent(null, //source
            null, // target,
            KeyEvent.KEY_PRESSED, // EventType
            null, // character
            null, // text
            keyCode, //
            false, // shiftDown
            false, // controlDown")
            false, // altDown,
            false // metaDown
    );
}
 
Example 15
Source File: AppUtils.java    From OpenLabeler with Apache License 2.0 4 votes vote down vote up
public static void fireKeyPressedEvent(Node target, KeyCode code) {
   KeyEvent event = new KeyEvent(KeyEvent.KEY_PRESSED, KeyEvent.CHAR_UNDEFINED, "", code, false, false, false, false);
   target.fireEvent(event);
   event.consume();
}
 
Example 16
Source File: WSRecorder.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void recordRawKeyEvent(RFXComponent r, KeyEvent e) {
    JSONObject event = new JSONObject();
    event.put("type", "key_raw");
    KeyCode keyCode = e.getCode();
    if (keyCode.isModifierKey()) {
        return;
    }
    if ((keyCode.isFunctionKey() || keyCode.isArrowKey() || keyCode.isKeypadKey() || keyCode.isMediaKey()
            || keyCode.isNavigationKey() || e.isControlDown() || e.isMetaDown() || e.isAltDown()
            || needManualRecording(keyCode)) && e.getEventType() == KeyEvent.KEY_PRESSED) {
        String mtext = buildModifiersText(e);
        event.put("modifiersEx", mtext);
        KeysMap keysMap = KeysMap.findMap(e.getCode());
        if (keysMap == KeysMap.NULL) {
            return;
        }
        String keyText;
        if (keysMap == null) {
            keyText = e.getText();
        } else {
            keyText = keysMap.toString();
        }
        event.put("keyCode", keyText);
    } else if (e.getEventType() == KeyEvent.KEY_TYPED && !e.isControlDown() && !needManualRecording(keyCode)) {
        char[] cs = e.getCharacter().toCharArray();
        if (cs.length == 0) {
            return;
        }
        for (char c : cs) {
            if (Character.isISOControl(c) && hasMapping(c)) {
                event.put("keyChar", getMapping(c));
            } else {
                event.put("keyChar", "" + c);
            }
        }
    } else {
        return;
    }
    recordEvent(r, event);
}
 
Example 17
Source File: TextAreaReadline.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(KeyEvent event) {
    if (event.getEventType() != KeyEvent.KEY_PRESSED) {
        return;
    }
    KeyCode code = event.getCode();
    switch (code) {
    case ENTER:
        positionToLastLine();
        boolean collect = false;
        if (area.getText().toString().endsWith(";")) {
            collect = true;
            area.setText(area.getText().substring(0, area.getText().length() - 1));
        }
        if (collect || event.isShiftDown()) {
            collectAction();
        } else {
            if (functionText.length() > 0) {
                collectAction();
            }
            enterAction(event);
            area.setEditable(false);
        }
        break;
    case UP:
        positionToLastLine();
        upAction(event);
        break;
    case DOWN:
        positionToLastLine();
        downAction(event);
        break;
    case LEFT:
    case D:
        if (event.isControlDown()) {
            event.consume();
            inputJoin.send(Channel.LINE, EMPTY_LINE);
        }
        break;
    default:
        break;
    }
}
 
Example 18
Source File: KeyEventHandler.java    From CrazyAlpha with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handle(KeyEvent keyEvent) {
    boolean mapShake = false;

    if (keyEvent.getEventType() == KeyEvent.KEY_PRESSED) {
        // 地图震动
        if (mapShake)
            Game.getInstance().getMapManager().getCurrentMap().start();
        ((CenterArc) Game.getInstance().getModelManager().get("CenterArc")).changeStrokeColor();

        String keyAlpha = keyEvent.getText().toUpperCase();
        Alpha alpha = (Alpha) Game.getInstance().getModelManager().get(keyAlpha);
        if (alpha == null) {
            Game.getInstance().getMissMusic().play();
            ((HPIndicator) Game.getInstance().getModelManager().get("HPIndicator")).miss();
            logger.info("missed {} !", keyAlpha);
            return;
        }

        if (alpha.getStatus() == ObjectStatus.ANIMATION) {
            Game.getInstance().debug("hint {}!", keyAlpha);
            Game.getInstance().getHintMusic().play();
            int gainScore = ((ScoreIndicator) Game.getInstance().getModelManager().get("ScoreIndicator")).hint(alpha);

            ScoreGadget scoreGadget = (ScoreGadget) Game.getInstance().getModelManager().getInvisibleModel(ScoreGadget.class);
            if (scoreGadget == null)
                scoreGadget = new ScoreGadget();
            scoreGadget.setText("+" + String.valueOf(gainScore));
            scoreGadget.setX(alpha.getX());
            scoreGadget.setY(alpha.getY());
            scoreGadget.setFillColor(alpha.getFillColor());
            Game.getInstance().getModelManager().register(scoreGadget, String.valueOf(RandomEx.nextInt()));
            scoreGadget.start();
            alpha.stop();
        } else {
            Game.getInstance().getMissMusic().play();
            ((HPIndicator) Game.getInstance().getModelManager().get("HPIndicator")).miss();
            logger.info("missed {} !", keyAlpha);
        }
    }

    if (keyEvent.getEventType() == KeyEvent.KEY_RELEASED) {
        if (mapShake)
            Game.getInstance().getMapManager().getCurrentMap().stop();
        Game.getInstance().getHintMusic().stop();
        Game.getInstance().getMissMusic().stop();
        ((CenterArc) Game.getInstance().getModelManager().get("CenterArc")).changeFillColor();
    }

    if (keyEvent.getCode() == KeyCode.ESCAPE) {
        if (Game.getInstance().getStatus() == GameStatus.PAUSE)
            Game.getInstance().resume();
        else if (Game.getInstance().getStatus() == GameStatus.RUNNING)
            Game.getInstance().pause();
    }
}
 
Example 19
Source File: DragSupport.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
public DragSupport(Node target, final KeyCode modifier, final MouseButton mouseButton, final Orientation orientation, final Property<Number> property, final double factor) {
    this.target = target;
    mouseEventHandler = new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            if (t.getEventType() != MouseEvent.MOUSE_ENTERED_TARGET
                    && t.getEventType() != MouseEvent.MOUSE_EXITED_TARGET) {
                lastMouseEvent = t;
            }
            if (t.getEventType() == MouseEvent.MOUSE_PRESSED) {
                if (t.getButton() == mouseButton
                        && isModifierCorrect(t, modifier)) {
                    anchor = property.getValue();
                    dragAnchor = getCoord(t, orientation);
                    t.consume();
                }
            } else if (t.getEventType() == MouseEvent.MOUSE_DRAGGED) {
                if (t.getButton() == mouseButton
                        && isModifierCorrect(t, modifier)) {
                    property.setValue(anchor.doubleValue()
                            + (getCoord(t, orientation) - dragAnchor) * factor);
                    t.consume();
                }
            }
        }
    };
    keyboardEventHandler = (KeyEvent t) -> {
        if (t.getEventType() == KeyEvent.KEY_PRESSED) {
            if (t.getCode() == modifier) {
                anchor = property.getValue();
                if (lastMouseEvent != null) {
                    dragAnchor = getCoord(lastMouseEvent, orientation);
                }
                t.consume();
            }
        } else if (t.getEventType() == KeyEvent.KEY_RELEASED) {
            if (t.getCode() != modifier && isModifierCorrect(t, modifier)) {
                anchor = property.getValue();
                if (lastMouseEvent != null) {
                    dragAnchor = getCoord(lastMouseEvent, orientation);
                }
                t.consume();
            }
        }
    };
    target.addEventHandler(MouseEvent.ANY, mouseEventHandler);
    target.addEventHandler(KeyEvent.ANY, keyboardEventHandler);
}
 
Example 20
Source File: FPSController.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleKeyEvent(KeyEvent event, boolean handle) {
    if (event.getEventType() == KeyEvent.KEY_PRESSED) {
        switch (event.getCode()) {
            case W:
                fwd = true;
                break;
            case S:
                back = true;
                break;
            case A:
                strafeL = true;
                break;
            case D:
                strafeR = true;
                break;
            case SHIFT:
                shift = true;
                if(up || down){
                    break;
                }
                speed = maxSpeed;                    
                break;
            case SPACE:
                if (!shift) {
                    up = true;
                } else if (shift) {
                    down = true;
                }
                break;
        }
    } else if (event.getEventType() == KeyEvent.KEY_RELEASED) {
        switch (event.getCode()) {
            case W:
                fwd = false;
                break;
            case S:
                back = false;
                break;
            case A:
                strafeL = false;
                break;
            case D:
                strafeR = false;
                break;
            case SHIFT:
                speed = minSpeed;
                shift = false;
                break;
            case SPACE:
                up = false;
                down = false;
                break;
        }
    }
}