I'm trying to make my program in JavaFX do something when I hold down the Shift key. When I do so, I only get one KEY_PRESSED
event, but when I hold down another button like "a". It works fine and I get multiple KEY_PRESSED
events. How do I fix this?
Here is the code:
public void keyPressed(KeyEvent keyEvent) {
System.out.println(keyEvent.getEventType());
}
The fxml file where I call the method:
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#keyPressed" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.drawController">
EDIT:
I figured it out. If I use the isShiftDown()
I get a single true, but nothing more. However, I realized that if I call the function on KEY_RELEASED
as well isShiftDown()
will return false so just waiting for it to turn false solved my issue.