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

[macos] Keys have different keycode on different keyboard layouts

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      Reproducible only on MacOS (currently it is 13.5.1)
      With JDK19+

      A DESCRIPTION OF THE PROBLEM :
      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

      See steps to reproduce

      REGRESSION : Last worked in version 17.0.8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      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 VERSUS ACTUAL BEHAVIOR :
      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

      ---------- BEGIN SOURCE ----------
      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);
              });
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. Capture1.png
          Capture1.png
          107 kB
        2. Example.java
          0.8 kB

            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: