I created a simple JavaFX application that receives input from the user in a TextField. I attached the KeyTyped event from SceneBuilder to the controller. My function looks like this:
@FXML private void keyTyped(KeyEvent event) {
System.out.println(event.getCode().equals(KeyCode.ENTER));
}
This function always prints out UNDEFINED when I type the enter key. Any ideas on how to fix this? Other letters I type seem to have the same problem as well.
KeyTyped
is a special event. It doesn't haveKeyCode
but hascharacter
set instead.See example for letter 'a':
and javadoc: http://docs.oracle.com/javafx/2/api/javafx/scene/input/KeyEvent.html#getCode()