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

[macosx] robot.keyPress do not generate key events (keyPressed and keyReleased) for function keys F13 to F19.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u66, 9
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b114
    • CPU:
      x86
    • OS:
      os_x

      Description

      Product(s) tested: JDK 1.8.0_66
      OS/architecture: MacOSX 10.10.5

      Reproducible: Always

      Is it a Regression: No
      Regression introduced in release/build: N/A

      Is it a platform specific issue: Yes
      [If platform specific issue] Is it a new (previously unsupported) OS/browser/mode testing: No
      [If new configuration testing] Issue specific to execution mode or OS/browser version: No

      Expected Result:
        The below code should return key codes for keys F1 to F19.

      Actual Result:
        The below code returns key codes for function keys F1 to F12 and for function keys F13 to F19 it doesn't return any key code.

      Test Program:

      import java.awt.AWTException;
      import java.awt.GridBagLayout;
      import java.awt.Robot;
      import java.awt.event.KeyEvent;
      import java.awt.event.KeyListener;
      import java.lang.reflect.InvocationTargetException;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.SwingUtilities;
      import static javax.swing.WindowConstants.EXIT_ON_CLOSE;

      class FunctionKeyCode extends JFrame {

          private static JFrame jframe;
          private static JLabel jlabel;
          private static KeyListener keyListener;
          private static int functionKeyArr[];
          private static final String OS = System.getProperty("os.name").toLowerCase();
          private static boolean functionKeyMatch;

          FunctionKeyCode() {
              FunctionKeyCode.functionKeyArr = new int[]{
                  KeyEvent.VK_F1,
                  KeyEvent.VK_F2,
                  KeyEvent.VK_F3,
                  KeyEvent.VK_F4,
                  KeyEvent.VK_F5,
                  KeyEvent.VK_F6,
                  KeyEvent.VK_F7,
                  KeyEvent.VK_F8,
                  KeyEvent.VK_F9,
                  KeyEvent.VK_F10,
                  KeyEvent.VK_F11,
                  KeyEvent.VK_F12,
                  KeyEvent.VK_F13,
                  KeyEvent.VK_F14,
                  KeyEvent.VK_F15,
                  KeyEvent.VK_F16,
                  KeyEvent.VK_F17,
                  KeyEvent.VK_F18,
                  KeyEvent.VK_F19
              };

              functionKeyMatch = true;
          }

          private void createAndShowGUI() throws InterruptedException, InvocationTargetException {

              SwingUtilities.invokeAndWait(new Runnable() {
                  @Override
                  public void run() {
                      jframe = new JFrame("Function Key Keycodes");
                      jlabel = new JLabel("");
                      jlabel.setFocusable(true);
                      jlabel.requestFocusInWindow();
                      jframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
                      jframe.add(jlabel);
                      jframe.setSize(200, 200);
                      jframe.setVisible(true);
                      jframe.setLayout(new GridBagLayout());

                      jlabel.addKeyListener(keyListener = new KeyListener() {

                          @Override
                          public void keyTyped(KeyEvent ke) {
                          }

                          @Override
                          public void keyPressed(KeyEvent ke) {
                              if (ke.getID() == KeyEvent.KEY_PRESSED) {
                                  
                                  switch (ke.getKeyCode()) {
                                      case KeyEvent.VK_F1:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F2:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F3:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F4:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F5:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F6:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F7:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F8:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F9:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F10:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F11:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F12:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F13:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F14:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F15:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F16:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F17:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F18:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      case KeyEvent.VK_F19:
                                          printMessage(ke.getKeyCode(), KeyEvent.getKeyText(ke.getKeyCode()));
                                          break;

                                      default:
                                          functionKeyMatch = false;
                                          System.err.println(KeyEvent.getKeyText(ke.getKeyCode()) + " is not a function key");
                                  }
                              }
                          }

                          @Override
                          public void keyReleased(KeyEvent ke) {
                          }
                      });
                  }
              });
          }

          private void printMessage(int keyCode, String keyText) {
              String message = "KeyCode for " + keyText + " : " + keyCode;
              System.out.println(message);
              jlabel.setText(message);
          }

          private void removeListener() {
              if (keyListener != null) {
                  jlabel.removeKeyListener(keyListener);
                  keyListener = null;
              }
          }

          private void generateFunctionKeyPress() {
              try {
                  Robot robot = new Robot();
                  robot.delay(1000);

                  for (int i = 0; i < functionKeyArr.length; i++) {
                      robot.keyPress(functionKeyArr[i]);
                      robot.keyRelease(functionKeyArr[i]);
                      robot.delay(500);
                  }
      // this.removeListener();

              } catch (AWTException e) {
                  System.err.println("Robot creation failed");
              }
          }

          public static void main(String args[]) throws InterruptedException, InvocationTargetException {

              if (!OS.contains("mac")) {
                  System.out.println("The test is applicable only to Mac OS X");
                  return;
              }

              FunctionKeyCode functionKeyObj = new FunctionKeyCode();
              functionKeyObj.createAndShowGUI();
              functionKeyObj.generateFunctionKeyPress();

              if (true == functionKeyMatch) {
                  System.out.println("Test Passed");
              } else {
                  System.out.println("Test Failed");
              }
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mhalder Manajit Halder (Inactive)
              Reporter:
              mhalder Manajit Halder (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: