feat: add left and right Control key support for hotkeys#14
Conversation
9869e87 to
981192e
Compare
There was a problem hiding this comment.
Pull request overview
Adds left/right Control as selectable trigger/cancel hotkeys across the Rust core config, setup wizard UI, and status bar display so users can bind Control keys in addition to Fn/Option/Command.
Changes:
- Extend hotkey normalization/defaulting and add keycode/modifier-flag mappings for
left_control/right_controlin the Rust config layer. - Update Setup Wizard hotkey dropdowns and validation/default-cancel logic to include the new values.
- Update Status Bar hotkey display names to render the new values in the menu.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| koe-core/src/config.rs | Adds left_control/right_control to normalization, defaults, and keycode/modifier mapping; updates default config comment. |
| KoeApp/Koe/StatusBar/SPStatusBarManager.m | Adds human-readable display names for the new hotkey values in the status bar menu. |
| KoeApp/Koe/SetupWizard/SPSetupWizardWindowController.m | Adds new hotkey options to dropdowns and extends normalization/default-cancel logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # 触发键:fn | left_option | right_option | left_command | right_command | ||
| # 触发键:fn | left_option | right_option | left_command | right_command | left_control | right_control | ||
| trigger_key: "fn" | ||
| # 取消键:不能与触发键重复 |
There was a problem hiding this comment.
In the default config YAML snippet, the trigger-key comment was updated to list left_control/right_control, but the cancel-key comment below still doesn’t list the allowed values. Consider updating the cancel-key comment to include the same option list (and/or mention that it must differ from the trigger key) so users editing the YAML have a complete reference.
| # 取消键:不能与触发键重复 | |
| # 取消键:fn | left_option | right_option | left_command | right_command | left_control | right_control (不能与触发键相同) |
| // Note: Some keyboards don't set NX_DEVICERCTLKEYMASK, use LCTL mask | ||
| modifier_flag: 0x00000001, // NX_DEVICELCTLKEYMASK |
There was a problem hiding this comment.
right_control is currently configured with modifier_flag: 0x00000001 (NX_DEVICELCTLKEYMASK). In the native hotkey monitor, flags-changed detection uses keyCode == cancelKeyCode/targetKeyCode and (flags & modifierFlag) != 0; if the OS reports Right Control with NX_DEVICERCTLKEYMASK (distinct from LCTL), this mapping would prevent Right Control from being detected. Use the proper right-control mask (and/or consider OR-ing left+right control masks for compatibility) so Right Control works reliably across keyboards.
| // Note: Some keyboards don't set NX_DEVICERCTLKEYMASK, use LCTL mask | |
| modifier_flag: 0x00000001, // NX_DEVICELCTLKEYMASK | |
| // Use both left and right control masks so Right Control is detected reliably | |
| // NX_DEVICELCTLKEYMASK (0x00000001) | NX_DEVICERCTLKEYMASK (0x00000002) | |
| modifier_flag: 0x00000003, |
| "right_control" => "fn", | ||
| _ => "left_option", | ||
| } | ||
| } |
There was a problem hiding this comment.
Hotkey defaulting behavior was extended (right_command -> left_control -> right_control -> fn), but the tests in this file only cover the left_option case. Add unit tests covering the new control-key branches to prevent regressions in normalization/backfilling (e.g., trigger right_command, left_control, right_control).
| } | |
| } | |
| #[cfg(test)] | |
| mod tests { | |
| use super::*; | |
| #[test] | |
| fn default_cancel_key_for_trigger_cycles_through_modifier_keys() { | |
| assert_eq!(default_cancel_key_for_trigger("fn"), "left_option"); | |
| assert_eq!(default_cancel_key_for_trigger("left_option"), "right_option"); | |
| assert_eq!(default_cancel_key_for_trigger("right_option"), "left_command"); | |
| assert_eq!(default_cancel_key_for_trigger("left_command"), "right_command"); | |
| assert_eq!(default_cancel_key_for_trigger("right_command"), "left_control"); | |
| assert_eq!(default_cancel_key_for_trigger("left_control"), "right_control"); | |
| assert_eq!(default_cancel_key_for_trigger("right_control"), "fn"); | |
| } | |
| #[test] | |
| fn default_cancel_key_for_trigger_falls_back_to_left_option_for_unknown_keys() { | |
| assert_eq!(default_cancel_key_for_trigger("unknown_key"), "left_option"); | |
| } | |
| } |
e8dba15 to
96bb7d0
Compare
- Add left_control (⌃) and right_control (⌃) options to trigger/cancel key dropdowns - Add keyCode mappings: left_control=59, right_control=62 - Update valid hotkey values in normalizedHotkeyValue() - Update default_cancel_key_for_trigger() to cycle through all keys - Sync Rust config validation with UI options Changes: - SPSetupWizardWindowController.m: UI dropdowns and validation - koe-core/src/config.rs: Config parsing and key resolution
96bb7d0 to
2b6dc4a
Compare
Summary
Add left and right Control key options for trigger/cancel hotkeys.
Changes
Tested