On Mon, 30 Jun 2025 16:58:00 GMT, Martin Fox <m...@openjdk.org> wrote:
> The Mac platform code figures out where characters are on the keyboard as the > user types. The character table is updated on every key press by calling a > registerKeyEvent: in GlassApplication. This character table is used to > resolve KeyCharacterCombination accelerators like Cmd + "+". > > On a US English layout when the user types Cmd + "+" on the main keyboard > they're actually typing Cmd + "=". There's special handling in macOS for this > combination that can cause two NSEvents to be sent and so there's special > handling in the Glass code so we don't process both events. When this special > case is invoked registerKeyEvent: isn't being called to update the character > table. This bug was introduced when code was consolidated in PR #1528. > > The fix is a simple one-liner. I've added a test for this in the > KeyboardTest.java program. It's an isolated test because it requires the > Robot to send events to hold down a modifier while a character key is > pressed. I also updated some obsolete comments and tweaked it to test all > KeyCharacterCombinations since they should now work reliably on all platforms. Well, now I’ve gone and re-written this PR. As stated earlier sometimes a single key press can lead to multiple calls to performKeyEquivalent. During testing I discovered that the way Glass checks for this doesn’t always work. Currently it tries to guess which key event might lead to a second one but there are cases where it guesses wrong (e.g. the Hebrew layout). I’ve decided to take a different approach, detecting and discarding the second event. The logic is: - Is the new key event not the current event (theEvent != NSApp.currentEvent)? - Are we still working on an earlier event (NSApp.currentEvent == lastKeyEvent)? If both these conditions are true we can ignore the new key event. I’ve reverted the changes to the manual test and added a system test. It covers a smattering of carefully selected keys including the combinations involved in this bug. Currently it’s restricted to macOS and Latin keyboards because the Hebrew keyboard on macOS is crazy. I will expand this to other platforms when I have time to do the testing. I’ve run this test on macOS using US English, French, German, Spanish, Hebrew, Devanagari, and a few other layouts. (About that Hebrew layout. When you hold down Command all the keys start behaving like a US English layout, including the punctuation keys. So the key you press to type a period is entirely different from the key that generates Cmd+period.) ------------- PR Comment: https://git.openjdk.org/jfx/pull/1837#issuecomment-3045927258