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

[macos] Regression: KeyEvent has different keycode on different keyboard layouts

    XMLWordPrintable

Details

    • b27
    • os_x

    Description

      Starting from JDK18 KeyEvents started to have different keycode on different keyboard layouts.
      Because of that shortcuts (like copy/paste) stopped to work on non-english locales.

      Everything works fine in JDKs 17 and older.

      It seems like this is the regression produced by this commit: https://github.com/openjdk/jdk/commit/47e7a42594f1c36f71cdf4d383080bf8d616b7e7

      With this code
      ```
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.KeyEvent;
      import java.awt.event.KeyListener;

      public class Example {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {
                  var frame = new JFrame();
                  frame.addKeyListener(new KeyListener() {
                      @Override
                      public void keyTyped(KeyEvent e) {

                      }

                      @Override
                      public void keyPressed(KeyEvent e) {
                          System.out.println("CODE " + KeyEvent.VK_C + " REAL CODE " + e.getKeyCode());
                      }

                      @Override
                      public void keyReleased(KeyEvent e) {

                      }
                  });
                  frame.setSize(new Dimension(200, 200));
                  frame.setVisible(true);
              });
          }
      }
      ```

      Steps to reproduce:
      1. Run the application
      2. Change locale to English
      3. Press cmd + C
      4. Change locale to Russian (may be on other it will also fail)
      5. Press cmd + C

      Expected:
      CODE 67 REAL CODE 67
      printed on both locales
      Actual -
      CODE 67 REAL CODE 67
      is printed on English locale
      CODE 67 REAL CODE 16778305
      is printed on Russian locale

      Attachments

        Issue Links

          Activity

            People

              achung Alisen Chung
              eushakov Egor Ushakov
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: