Skip to content

Better key handling for macOS and Qt#4216

Merged
freakboy3742 merged 9 commits intobeeware:mainfrom
corranwebster:better-key-handling
Mar 4, 2026
Merged

Better key handling for macOS and Qt#4216
freakboy3742 merged 9 commits intobeeware:mainfrom
corranwebster:better-key-handling

Conversation

@corranwebster
Copy link
Contributor

@corranwebster corranwebster commented Mar 3, 2026

On macOS, this PR minimises the use of hardware key codes for interpreting key events on macOS in favour of using the various character methods to determine the intended key press based on the keyboard layout. It doesn't yet add toga support for non-US characters, but should improve things like mapping keys correctly on an AZERTY layout keyboard.

On Qt, this PR fixes some missing key codes and fixes some issues raised by new tests.

Ref #2428.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@corranwebster corranwebster changed the title Better key handling for macOS Better key handling for macOS and Qt Mar 4, 2026
@corranwebster corranwebster marked this pull request as ready for review March 4, 2026 16:25
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little difficult for me to live test without access to a UK (or other European) keyboard layout, but I can't fault the logic, and it all seems to work as expected.

@freakboy3742 freakboy3742 merged commit b0ef8c4 into beeware:main Mar 4, 2026
114 of 115 checks passed
@corranwebster
Copy link
Contributor Author

For future reference, the way I've been testing this on macOS is to add new keyboard layouts in keyboard settings and then switch between them (I already had this set up for AU and GB) with a widget modified to get keyboard focus and events and report them. You don't get the exact same physical layout as a native language keyboard, but the key codes map correctly as best I can tell.

Although it is surprising when you have your keyboard set to something like Slovenian to test, and then try to type some code and it comes out not quite right because you forgot to set it back to English...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants