Yupp
Yupp

Reputation: 325

javafx avoid pause at the beginning when pressing key

I use the key LEFT and RIGHT to move the position of my view. When I press and hold down the key the view moves to the side, pauses a short time, and then keeps moving until I release the key. Is it possible to skip the pause between the first action and the actions afterwards?

gridPane.setOnKeyPressed(
    e -> {
        e.consume();
        if (e.getCode() == KeyCode.RIGHT)
        {
            moveMarkerNextPositionWithKeys(e.isAltDown());
        }
        else if (e.getCode() == KeyCode.LEFT)
        {
            moveMarkerPreviousPositionWithKeys(e.isAltDown());
        }
    }
);

Upvotes: 2

Views: 368

Answers (1)

bakcsa83
bakcsa83

Reputation: 424

The pause you are referring to is the keyboard repeat delay which can be set in the OS. E.g on windows Control panel->Keyboard->Speed->Repeat delay. It cannot be overridden. You need to implement a timer which starts with a keypressed event and moves your view until a keyreleased event.

Upvotes: 4

Related Questions