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

[linux] Special Characters input via composition do not produce correct KeyEvents on Linux OS

XMLWordPrintable

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Linux Xavier 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      In RichTextFX (https://github.com/TomasMikula/RichTextFX/issues/280), a custom built text area that does not extend `TextInputControl` cannot input special characters on Linux-based OS. However, special characters can be inputted on Windows or Mac OS

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In the given source code, press the Compose key, the ` key, and the A key. Then click on the TextArea and do the same thing.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Strings outputted from the key events should be the same, indicating that a special character was inputted, not the composition keys that composed it.
      ACTUAL -
      The code treats each composition key event as a regular keys being pressed. It does not interpret the key presses as a special-character-input event.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.TextArea;
      import javafx.scene.input.KeyCode;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.VBox;
      import javafx.scene.shape.Circle;
      import javafx.stage.Stage;

      public class SpecialArea extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception {
              Circle rtfxArea = new Circle(50);
              TextArea jfxArea = new TextArea();

              // output the column headers
              outputColumnHeaders();

              // setup listener
              EventHandler<KeyEvent> output = e -> {

                  StringBuilder sb = new StringBuilder();
                  String type = e.getEventType().toString();
                  sb
                          .append(type.substring(4, type.length()))
                          .append("\t").append(e.getCharacter())
                          .append("\t").append(e.getCode())
                          .append("\t").append(e.getText())
                          .append("\t").append(e.isControlDown())
                          .append("\t").append(e.isShiftDown())
                          .append("\t").append(e.isAltDown())
                          .append("\t").append(e.isMetaDown())
                          .append("\t").append(e.isShortcutDown());
                  System.out.println(sb.toString());
              };

              // add event filter
              rtfxArea.addEventFilter(KeyEvent.ANY, output);
              jfxArea.addEventFilter(KeyEvent.ANY, output);

              Scene scene = new Scene(new VBox(rtfxArea, jfxArea), 500, 500);
              // re-output headers on S and switch to other area
              scene.addEventHandler(KeyEvent.KEY_RELEASED, e -> {
                  if (e.getCode() == KeyCode.S) {
                      System.out.println("\n--- Switching to next area ---\n");
                      outputColumnHeaders();
                      if (rtfxArea.isFocused()) {
                          jfxArea.requestFocus();
                      } else {
                          rtfxArea.requestFocus();
                      }
                      e.consume();
                  }
              });
              primaryStage.setScene(scene);
              primaryStage.show();
              rtfxArea.requestFocus();
          }

          private void outputColumnHeaders() {
              StringBuilder sb = new StringBuilder();
              sb.append("Event Type")
                      .append("\tChar")
                      .append("\tCode")
                      .append("\tText")
                      .append("\tCTRL")
                      .append("\tSHIFT")
                      .append("\tALT")
                      .append("\tMETA")
                      .append("\tSHORT");
              System.out.println(sb.toString());
          }
      }
      ---------- END SOURCE ----------

            ssadetsky Semyon Sadetsky (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: