JDK-8147834 : [macosx] KeyEvents for function keys F17, F18, F19 return keyCode 0
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u66,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2016-01-06
  • Updated: 2016-03-18
  • Resolved: 2016-02-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b110Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Darwin machinename 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64


EXTRA RELEVANT SYSTEM CONFIGURATION :
Using an Apple USB Keyboard with numeric keyboard Norwegian - like this one: http://www.apple.com/uk/shop/product/MB110H/B/apple-keyboard-with-numeric-keypad-norwegian

A DESCRIPTION OF THE PROBLEM :
The function keys F17, F18 and F19 return a keyCode value of "0" instead of the values described in https://docs.oracle.com/javase/7/docs/api/constant-values.html#java.awt.event.KeyEvent.VK_F17 through VK_F19. This makes it impossible to use these last three function keys on the keyboard in Java applications. F1 through F16 work as expected.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I originally reported this as a bug in the Google Android Studio product. There is a simple test case attached here: https://code.google.com/p/android/issues/detail?id=184996#c2

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When pressing F12, F16, F17, F18, F19 the sample application should display:

F12: 123
F16: 61443
F17: 61444
F18: 61445
F19: 61446
ACTUAL -
When pressing F12, F16, F17, F18, F19 the sample application displays:

F12: 123
F16: 61443
Other key: 0
Other key: 0
Other key: 0


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Frame;
import java.awt.KeyboardFocusManager;
import java.awt.TextArea;
import java.awt.event.KeyEvent;

class Main extends Frame {
  Main() {
    TextArea textArea = new TextArea("Press A Key");
    textArea.setBounds(30, 100, 200, 60);

    add(textArea);
    setSize(300, 300);
    setLayout(null);
    setVisible(true);

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(ke -> {
      if (ke.getID() == KeyEvent.KEY_PRESSED) {
        switch (ke.getKeyCode()) {
          case KeyEvent.VK_F12:
            textArea.setText("F12: " + ke.getKeyCode());
            break;
          case KeyEvent.VK_F16:
            textArea.setText("F16: " + ke.getKeyCode());
            break;
          case KeyEvent.VK_F17:
            textArea.setText("F17: " + ke.getKeyCode());
            break;
          case KeyEvent.VK_F18:
            textArea.setText("F18: " + ke.getKeyCode());
            break;
          case KeyEvent.VK_F19:
            textArea.setText("F19: " + ke.getKeyCode());
            break;
          default:
            textArea.setText("Other key: " + ke.getKeyCode());
        }
      }
      return false;
    });
  }
  public static void main(String args[]) {
    Main f = new Main();
  }
}

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


Comments
The automated test case to test the fix is covered in the test case of the issue https://bugs.openjdk.java.net/browse/JDK-8149456. Test case file: java/awt/keyboard/AllKeyCode/AllKeyCode.java tests both the issues: https://bugs.openjdk.java.net/browse/JDK-8149456 and https://bugs.openjdk.java.net/browse/JDK-8147834 Therefore issue "https://bugs.openjdk.java.net/browse/JDK-8150230" will be closed as "won't fix" as there is no need of a separate test case to test this issue.
18-03-2016

https://bugs.openjdk.java.net/browse/JDK-8150230 is created for the automated test case. The automated test case is under development and will be available after issue https://bugs.openjdk.java.net/browse/JDK-8149456 is resolved.
19-02-2016

Webrev link: http://cr.openjdk.java.net/~mhalder/8147834/webrev.00
16-02-2016

The function key F20 is not defined on MacOS platform and it will also return 0. F20 key is a valid key on MacOS and also defined in Java documentation. Therefore fix for F20 need to be added along with this issue fix.
12-02-2016

Fix explaination: The fix is to add the key codes for F17, F18 and F19 on the MacOS X side. The values of the keys were referred from following file /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h on MacOS X. Fix is also added for function key F20 because F20 key is valid in Java and MacOS X the and need to be supported on MacOS. But this key can���t be tested with the normal USB keyboard because it has function key till F19. Testing the Fix: The fix was tested manually using the code present in the description. Right now there is no automated test case available for this fix. While writing the test case it was found that robot.keyPress is failing for function keys F13 to F19 (also will fail for F20). An issue is created for the same problem with Jira id: https://bugs.openjdk.java.net/browse/JDK-8149456 An automated test case will be provided after fixing issue JDK-8149456.
12-02-2016

The function keys F17, F18 and F19 are returning key code 0 because the key codes for these keys are not defined on the MacOS X platform.
04-02-2016

P3 - ILW (M, M, M)
21-01-2016

The problem is reproduced on MacOS 10.10.5 with JDK 9.1 Keyboard used: USB keyboard with Input Sources "U.S."
21-01-2016