On Mon, 18 Sep 2023 20:51:47 GMT, Martin Fox <d...@openjdk.org> wrote:
>> I am running this on macOS 13.5.1 with several keyboard layouts enabled. >> >> A test that does keyPress(KeyCode.A) followed by a keyRelease(KeyCode.A) >> generates the following sequence of events: >> >> With the US layout: >> >> >> KeyEvent [source = TextArea@7da926e[styleClass=text-input text-area], target >> = TextArea@7da926e[styleClass=text-input text-area], eventType = >> KEY_PRESSED, consumed = false, character = , text = a, code = A] >> KeyEvent [source = TextArea@7da926e[styleClass=text-input text-area], target >> = TextArea@7da926e[styleClass=text-input text-area], eventType = KEY_TYPED, >> consumed = false, character = a, text = , code = UNDEFINED] >> KeyEvent [source = TextArea@7da926e[styleClass=text-input text-area], target >> = TextArea@7da926e[styleClass=text-input text-area], eventType = >> KEY_RELEASED, consumed = false, character = , text = a, code = A] >> >> >> With the French layout: >> >> >> KeyEvent [source = TextArea@75ffb50a[styleClass=text-input text-area], >> target = TextArea@75ffb50a[styleClass=text-input text-area], eventType = >> KEY_PRESSED, consumed = false, character = , text = q, code = A] >> KeyEvent [source = TextArea@75ffb50a[styleClass=text-input text-area], >> target = TextArea@75ffb50a[styleClass=text-input text-area], eventType = >> KEY_TYPED, consumed = false, character = q, text = , code = UNDEFINED] >> KeyEvent [source = TextArea@75ffb50a[styleClass=text-input text-area], >> target = TextArea@75ffb50a[styleClass=text-input text-area], eventType = >> KEY_RELEASED, consumed = false, character = , text = q, code = A] >> >> >> And with a cyrillic layout it generates whatever cyrillic letter is mapped >> to the key. So, basically, KeyCode is more like a scan code, which means >> there is no reliable way to test key bindings using Robot, unless we limit >> ourselves (and the test) to the US layout. Or is there another way? >> >> <img width="612" alt="Screenshot 2023-09-18 at 13 19 51" >> src="https://github.com/openjdk/jfx/assets/107069028/8bd8745c-8973-449f-bf17-0473f5c0e0b6"> > > This is the behavior we saw on the Mac before PR #425 was integrated. As of > JavaFX 21 keyPress(KeyCode.A) should generate an 'a' and never a 'q' on all > Latin layouts and all platforms (on a Cyrillic layout you'll still get a > Cyrillic character). > > I can't reproduce this with the test app > (tests/manual/events/KeyboardTest.java). Is there a test in this PR I should > be trying? You could try this code (using this PR's code): public class KeyboardLayoutTest extends TextInputBehaviorRobotTest<TextArea> { public KeyboardLayoutTest() { super(new TextArea()); } @BeforeEach @Override public void beforeEach() { super.beforeEach(); control.setWrapText(true); } @Test public void testTyping() throws Exception { KeyCode[] codes = { KeyCode.A }; execute( exe(() -> { control.addEventFilter(KeyEvent.ANY, (ev) -> { System.out.println(ev); ev.consume(); }); }) ); for(KeyCode cd: codes) { Util.runAndWait(() -> { robot.keyPress(cd); robot.keyRelease(cd); }); } } } ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/1221#discussion_r1329290052