RFR: 8150709: Mac OSX and German Keyboard Layout (Y/Z) [v5]

Martin Fox duke at openjdk.java.net
Mon Dec 20 19:21:36 UTC 2021


On Thu, 16 Dec 2021 21:40:47 GMT, Martin Fox <duke at openjdk.java.net> wrote:

>> This PR adds code to ensure that KeyCodeCombinations match KeyEvents as expected by more accurately mapping from a Mac key code to a Java key code based on the user’s active keyboard layout (the existing code assumes a US QWERTY layout). The new code first identifies a set of Mac keys which can produce different characters based on the user’s keyboard layout. A Mac key code outside that area is processed exactly as before. For a key inside the layout-sensitive area the code calls UCKeyTranslate to translate the key to an unshifted ASCII character based on the active keyboard and uses that to determine the Java key code.
>> 
>> When performing the reverse mapping for the Robot the code first uses the old QWERTY mapping to find a candidate key. If it lies in the layout-sensitive area the code then scans the entire area calling UCKeyTranslate until it finds a match. If the key lies outside the layout-sensitive area it’s processed exactly as before.
>> 
>> There are multiple duplicates of these bugs logged against Mac applications built with JavaFX.
>> 
>> https://bugs.openjdk.java.net/browse/JDK-8090257 Mac: Inconsistent KeyEvents with alternative keyboard layouts
>> https://bugs.openjdk.java.net/browse/JDK-8088120 [Accelerator, Mac] CMD + Z accelerator is not working with French keyboard
>> https://bugs.openjdk.java.net/browse/JDK-8087915 Mac: accelerator doesn't take into account azerty keyboard layout
>> https://bugs.openjdk.java.net/browse/JDK-8150709 Mac OSX and German Keyboard Layout (Y/Z)
>
> Martin Fox has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - Merge branch 'master' into macshortcut
>  - Fixed whitespace error.
>  - A small number of keyboard layouts require the Option key to reach
>    critical letters like 'Q'. Added a third probe (after Command and
>    Shift+Command) to look for letters that require Option. The
>    keyboards in question are Azeri, Turkmen, and the Sami layouts.
>  - The code now queries both the shifted and unshifted characters for a key
>    favoring digits and letters over everything else. This ensures we catch
>    the digits on the French layout without interfering with Dvorak.
>  - Mac - generate KeyCodes that match user's active keyboard layout.

Let me start by saying that I already have two small changes to make to this PR. One is a fix for a bug in the Robot code. The other is a small tweak to the way dead keys are assigned key codes (I recently did a deep dive on dead keys). I will submit the changes in the next day or two.

The regression that concerns me the most is losing access to key codes that are likely to be bound to KeyCodeCombination shortcuts. This includes the fixed-function keys (like KeyCode.SPACE and KeyCode.TAB) as well as KeyCode.A through KeyCode.Z. The attached KeyboardTest app contains a manual test for most of these keys (it's the "A-Z test" button at the bottom).

With this PR the Robot implementation for letter keys will be good enough on all platforms that we can expand automated testing. But there's already a basic test for this (test.robot.javafx.scene.RobotTest) that fails on the Mac if the layout is French. I'm not sure why that failure was never reported. Expanding the test to cover more keys won't do any good if the test isn't run against non-US layouts and that requires manual setup.

On every platform the Robot implementation has bugs related to punctuation and symbols. The fixes aren't that deep and I'll be submitting PR's for them (this PR already fixes the Mac). Once those bugs are fixed the testing will still be limited and manual. You have to know the current layout to craft a useful test and there's no API for querying the layout much less forcing it to the one you want to test.

The KeyboardTest app has some limited tests specific to US, German, and French layouts that are useful for sanity checking. Unfortunately the attached version also include checks for KeyCharacterCombination matching which fail on the Mac (for now). I will tweak the app to make that part of the test optional. I was planning to submit this app as a manual test once the various platforms were in better shape.

-------------

PR: https://git.openjdk.java.net/jfx/pull/425


More information about the openjfx-dev mailing list