Repository navigation
Add a Key.CONTROL modifier for the physical Control key - #4884
Merged
Merged
Conversation
Core defines Key.CONTROL; each backend maps it to its native Control modifier. On macOS that's the same key as MOD_3; on Linux and Windows it's the same key as MOD_1. Key events still report the generic MOD_n modifier.
freakboy3742
approved these changes
Nov 10, 2026
freakboy3742
left a comment
Member
There was a problem hiding this comment.
Looks good; one minor tweak ensuring that the probe contains all the platform-specific definitions, rather than needing a current_platform check in the test code.
| from toga.keys import Key | ||
|
|
||
| # The generic modifier that the backend's physical Control key is reported as. | ||
| CONTROL = Key.MOD_3 if toga.platform.current_platform == "macOS" else Key.MOD_1 |
Member
There was a problem hiding this comment.
The definition of the mapping should be on the probe, rather than relying on current_platform.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Toga's generic modifiers (
MOD_1,MOD_2,MOD_3) follow each platform's precedence, so there's no way to ask for the Control key specifically: it'sMOD_3on macOS andMOD_1on Linux and Windows. This addsKey.CONTROLfor the physical Control key. Core only defines the name; each backend maps it to its own native Control modifier:Key.CONTROLmaps toNSEventModifierFlagControlMOD_3<Control>(not<Primary>, which is Command on macOS)MOD_1Keys.ControlMOD_1ControlModifierMOD_1<Ctrl>MOD_1iOS, Textual and Web don't support keyboard shortcuts, so they have nothing to map.
When a native key event is converted back into a Toga key, Control is still reported as the generic modifier (
MOD_1orMOD_3), so existing results don't change. Qt and Winforms used one modifier table for both directions, so they get a separate shortcut-only table; otherwise a Control key event would report bothMOD_1andCONTROL. On Winforms, a shortcut that combinesMOD_1andCONTROLshows "Ctrl" only once in the menu label.Tests: a
Key.CONTROL + "a"case in the testbed key round-trip test, which expectsMOD_3on macOS andMOD_1elsewhere. The GTK probe now parses<Control>. Run locally on the macOS testbed (fails without the Cocoa mapping, passes with it); GTK, Qt and Winforms are exercised by CI.PR Checklist:
Assisted-by: Claude Code (Claude Opus 5.5)