JDK-8094298 : KeyCombination matching is broken (at least on Linux)
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: 8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-09-24
  • Updated: 2015-06-12
  • Resolved: 2014-09-25
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 8
8u40Fixed
Related Reports
Relates :  
Description
Below is a test case that shows how KeyCombination matching is broken.
I'm using JDK 8u40-b02 on Linux.

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.input.KeyCharacterCombination;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;


public class KeyCombinationTest {

    public static void main(String[] args) {
        new JFXPanel(); // initialize JavaFX

        KeyCharacterCombination a = new KeyCharacterCombination("a");
        KeyCharacterCombination A = new KeyCharacterCombination("A");
        KeyCharacterCombination b = new KeyCharacterCombination("b");
        KeyCharacterCombination B = new KeyCharacterCombination("B");
        KeyCharacterCombination LF = new KeyCharacterCombination("\n");
        KeyCharacterCombination CR = new KeyCharacterCombination("\r");
        KeyCharacterCombination TAB = new KeyCharacterCombination("\t");

        KeyEvent event = new KeyEvent(KeyEvent.KEY_TYPED, "a", "", KeyCode.UNDEFINED, false, false, false, false);

        System.out.println("a match a: " + a.match(event)); // false (!!!)
        System.out.println("A match a: " + A.match(event)); // true (!!!)
        System.out.println("b match a: " + b.match(event)); // false
        System.out.println("B match a: " + B.match(event)); // true (!!!)
        System.out.println("LF match A: " + LF.match(event)); // true (!!!)
        System.out.println("CR match A: " + CR.match(event)); // true (!!!)
        System.out.println("TAB match A: " + TAB.match(event)); // true (!!!)

        Platform.exit();
    }

}


OUTPUT:

a match a: false
A match a: true
b match a: false
B match a: true
LF match A: true
CR match A: true
TAB match A: true
Comments
Changeset: http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/d71ccbe411d4
25-09-2014

+1
24-09-2014

Look at the javadoc of KeyCharacterCombination.match(), where this is explained.
24-09-2014

Hi Martin, > 3) TYPED events should never match. I extended this to all evens with UNDEFINED keycode (which includes all TYPED). My expectation was that KeyCharacterCombination should match KEY_TYPED events, while KeyCodeCombination should match KEY_PRESSED and KEY_RELEASED events. Why is my expectation wrong?
24-09-2014

[Edit: Chien is the right guy for scene graph, sorry Vadim] Chien, Dave, as you are the code owners now, I'm asking you for a review: http://cr.openjdk.java.net/~msladecek/rt-38778/webrev.00/ There are multiple issues here. 1) Capital letters are not converted correctly by Toolkit.getToolkit().getKeyCodeForChar() as there were not in the table. I fixed this. 2) LF, CR, TAB fail to convert using gdk_unicode_to_keyval() for some reason. I can't find any (documented) reason for this. Maybe a bug in GDK? We can workaround it by special-casing all of these characters or find a different way for conversion. I will file this as a separate issue. 3) TYPED events should never match. I extended this to all evens with UNDEFINED keycode (which includes all TYPED). Thanks.
24-09-2014