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

KeyEvent.getModifiers() returns inconsistent values for ALT keys

    XMLWordPrintable

Details

    • b21
    • Not verified

    Backports

      Description

        Seeing some inconsistent behaviour with KeyEvent.getModifiers() for right and left ALT keys in JDK > 1.8

        /**
         *
         * Steps : Run this file using JDK 1.8, Windows, Mac OSX,
         * Invoke Left-ALT key, note keyEvent.getModifiers() is 8(InputEvent.ALT_MASK)
         * Invoke right-ALT key, getModifiers() returns 8.
         *
         * Run using JDK 11, Windows
         * Invoke Left-ALT key, note keyEvent.getModifiers() is 8
         * Invoke right-ALT key, getModifiers() returns 40.
         * Switching between left and right alt keys returns same result.
         *
         * Run using JDK 11, Mac
         * Invoke Left-ALT key, note keyEvent.getModifiers() is 8
         * Invoke right-ALT key, getModifiers() returns 40(InputEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK).
         * Now again press left alt key,it now starts returning getModifiers as 40, getModifiersEx also returns different value.
         *
         * Issues/Questions:
         * KeyEvent.getModifiers() for ALT keys has changed after JDK 1.8. Is this expected behaviour?
         * Is getModifiers() expected to be different for Left ALT key and Rt ALT keys on Windows?
         * Is getModifiers, getModifersEx expected to return diff values on Mac and Windows?
         * In Mac, left alt key getModifiers, getModifiersEx changing after rt alt key is selected, on JDK 11, looks to be a bug.
         */
        public class JavaApplication1 {

            public static void main(String[] args) {
               JTextField comp = new JTextField();
               comp.addKeyListener(new MyListener());
               JFrame f = new JFrame();
               f.add(comp);
               f.setSize(100,100);
               f.setVisible(true);
            }
        }
            class MyListener implements KeyListener {

            public MyListener() {
            }

            @Override
            public void keyTyped(KeyEvent e) {
                
            }

            @Override
            public void keyPressed(KeyEvent e) {
                System.out.println("ModEx : " +e.getModifiersEx());
                System.out.println("Mod : " +e.getModifiers());
                System.out.println("-----------");
                
                
            }

            @Override
            public void keyReleased(KeyEvent e) {
                
            }
            
        }


        Attachments

          Issue Links

            Activity

              People

                kaddepalli Krishna Addepalli
                rtaneja Reema Taneja
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: