I'm making a video game with a simple inventory system. I'm trying to make it so that whenever you press the "Z" key it would show or hide the inventory GUI. I don't know why, but the KEY_TYPED key events aren't working. The KEY_PRESSED and KEY_RELEASED key events are working perfectly fine.
Here is my key event handler class:
public static KeyCode handle(javafx.scene.input.KeyEvent e) {
if (e.getEventType() == javafx.scene.input.KeyEvent.KEY_PRESSED) {
e.consume();
return e.getCode();
}
if (e.getEventType() == javafx.scene.input.KeyEvent.KEY_RELEASED) {
e.consume();
return e.getCode();
}
if (e.getEventType() == javafx.scene.input.KeyEvent.KEY_TYPED) {
e.consume();
return e.getCode();
}
return null;
}
Here is where I'm using the key events:
primaryStage.getScene().setOnKeyTyped(event -> {
KeyCode e = KeyEvent.handle(event);
if (e == KeyCode.Z) {
System.out.println("test");
}
});
When I tried pressing the key, it did absolutely nothing.