The character value returned for a KEY_TYPED event for the BACKSPACE, DELETE and ESCAPE keys should contain the corresponding ASCII codes but instead contains an empty string.
Additionally the numeric keypad ENTER key generates a character string with ASCII 3, rather than 13. On Linux the numeric keypad ENTER key does not generate a KEY_TYPED event at all. On Windows the numeric keypad ENTER key generates ASCII 13 for the KEY_TYPED character.
The following program can be used to demonstrate this.
{code:java}
import java.util.Arrays;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class EnterKeyTyped extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
var list = new ListView(FXCollections.observableArrayList("Click Here", "Then press BACKSPACE, DELETE, or ESCAPE"));
list.setMaxHeight(90);
var textArea = new TextArea();
textArea.setWrapText(true);
list.addEventFilter(KeyEvent.KEY_TYPED, ke -> {
textArea.setText(ke.toString()+"\nke.getCharacter().getBytes() = "+Arrays.toString(ke.getCharacter().getBytes()));
});
var vbox = new VBox(4, new Label("Focus on the ListView and type BACKSPACE, DELETE, or ESCAPE"), list, textArea);
var scene = new Scene(vbox);
primaryStage.setTitle("KeyEvent.KEY_TYPED missing Character for BACKSPACE, DELETE, or ESCAPE");
primaryStage.setMinWidth(800);
primaryStage.setScene(scene);
primaryStage.show();
}
}
{code}
Additionally the numeric keypad ENTER key generates a character string with ASCII 3, rather than 13. On Linux the numeric keypad ENTER key does not generate a KEY_TYPED event at all. On Windows the numeric keypad ENTER key generates ASCII 13 for the KEY_TYPED character.
The following program can be used to demonstrate this.
{code:java}
import java.util.Arrays;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class EnterKeyTyped extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
var list = new ListView(FXCollections.observableArrayList("Click Here", "Then press BACKSPACE, DELETE, or ESCAPE"));
list.setMaxHeight(90);
var textArea = new TextArea();
textArea.setWrapText(true);
list.addEventFilter(KeyEvent.KEY_TYPED, ke -> {
textArea.setText(ke.toString()+"\nke.getCharacter().getBytes() = "+Arrays.toString(ke.getCharacter().getBytes()));
});
var vbox = new VBox(4, new Label("Focus on the ListView and type BACKSPACE, DELETE, or ESCAPE"), list, textArea);
var scene = new Scene(vbox);
primaryStage.setTitle("KeyEvent.KEY_TYPED missing Character for BACKSPACE, DELETE, or ESCAPE");
primaryStage.setMinWidth(800);
primaryStage.setScene(scene);
primaryStage.show();
}
}
{code}
- relates to
-
JDK-8119340 Gtk: KEY_TYPED event for ENTER does not have character on Linux
-
- Resolved
-