RFR: 8274967: KeyCharacterCombinations for punctuation and symbols fail on non-US keyboards
Martin Fox
duke at openjdk.java.net
Fri Dec 10 17:27:18 UTC 2021
On Mon, 15 Nov 2021 20:13:11 GMT, Martin Fox <duke at openjdk.java.net> wrote:
> The code that maps from a Windows virtual key code to a Java key code in `getKeyCodeForChar` did not match the similar code in `ViewContainer::HandleViewKeyEvent`. The OEM keys are assigned to printable punctuation and symbols in ways which vary across layouts and even keyboards. To determine the correct Java key code you have to query the layout to determine the character the key would generate without modifiers and map that character to the key code. `ViewContainer::HandleViewKeyEvent` did this, `getKeyCodeForChar` did not. This PR copies a few snippets of code from `ViewContainer::HandleViewKeyEvent` to make the two algorithms match.
Thanks for catching this, I should have investigated dead keys in more detail earlier.
The test case code should exclude dead keys since they're not eligible as shortcuts on Windows. If the Control key is down when a dead key is pressed both Windows and JavaFX just ignore it. If some other modifier is down (say, Alt) Windows will treat it as a dead key and JavaFX should not treat it as a shortcut.
In a perfect world `getKeyCodeForChar` would return `KeyCode.UNDEFINED` for dead keys to disable shortcut processing. But I can't figure out way of detecting that the key is a dead key. `MapVirtualKeyEx` is supposed to tell me that but doesn't. `ToUnicodeEx` would do the job but has side effects in the global keyboard state so it is off-limits. The best I can do is what the code already does and return a non-dead `KeyCode` that will never match the current `KeyEvent`.
-------------
PR: https://git.openjdk.java.net/jfx/pull/672
More information about the openjfx-dev
mailing list