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

KeyCharacterCombination for "+" does not work on US QWERTY keyboard layout

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: openjfx11, openjfx16, openjfx17
    • Fix Version/s: tbd
    • Component/s: javafx

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 18.04 x86_64
      JavaFX 17
      JavaFX 11
      OpenJDK 11.0.11

      A DESCRIPTION OF THE PROBLEM :
      KeyCharacterCombinations involving characters that require the Shift key to type (like "+" on a US keyboard) never match any key event and do not work. The Linux implementation of the Toolkit call getKeyCodeForChar does not reference the current keyboard layout and so can't return correct results. For example, if the argument is "+" getKeyCodeForChar returns KeyCode.PLUS on all layouts. On a US layout it should return KeyCode.EQUALS.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the included test app.
      Switch to a US English keyboard layout.
      Press Ctrl+L to verify the app has focus.
      Press Ctrl+'+'.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      On the Ctrl+L press you should see "KeyCodeCombination worked" on the console.
      On the Ctrl+'+' press you should see "KeyCharacterCombination worked" on the console.
      ACTUAL -
      Only Ctrl+L generates console output. The Ctrl+'+' key event is ignored.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.Pane;
      import javafx.stage.Stage;
      import javafx.scene.input.KeyCode;
      import javafx.scene.input.KeyCombination;
      import javafx.scene.input.KeyCharacterCombination;
      import javafx.scene.input.KeyCodeCombination;

      public class KeyCharComboTest extends Application {
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
              primaryStage.setTitle("KeyCharacterCombination test");
              Pane root = new Pane();
              Scene scene = new Scene(root, 300, 250);
              scene.getAccelerators().put(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN),
                      () -> System.out.println("KeyCodeCombination worked"));
              scene.getAccelerators().put(new KeyCharacterCombination("+", KeyCombination.SHORTCUT_DOWN),
                      () -> System.out.println("KeyCharacterCombination worked"));
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mfox Martin Fox
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: