Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8299394

KEY_TYPED event for BACKSPACE, DELETE and ESCAPE do not have a character value on macOS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx19
    • javafx
    • None
    • Java 17.0.5
      JavaFX 19.0.1
      macOS 13.2

    • x86
    • os_x

      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}

            mfox Martin Fox
            swpalmer Scott Palmer
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: