Skip to content

fix(macos): track Fn flag bit in FlagsChanged handler#3

Open
that-yolanda wants to merge 1 commit into
jamiepine:mainfrom
that-yolanda:fix/macos-fn-flag-bit
Open

fix(macos): track Fn flag bit in FlagsChanged handler#3
that-yolanda wants to merge 1 commit into
jamiepine:mainfrom
that-yolanda:fix/macos-fn-flag-bit

Conversation

@that-yolanda

@that-yolanda that-yolanda commented Jun 20, 2026

Copy link
Copy Markdown

Problem

On macOS the Fn key is completely unobservable — pressing it produces no KeyDown/KeyUp events, even though Key::Function exists and kVK_Function (keycode 63) is already mapped in the keycode table.

Root cause

Key::Function is mapped in the keycode table (63 => Key::Function), but flag_bit_for_key() in src/platform/macos/tap.rs has no matching arm. So every Fn FlagsChanged event falls through to the _ => 0 fallback and is silently dropped:

fn flag_bit_for_key(key: Key) -> u64 {
    match key {
        // ...
        Key::CapsLock => CGEVENT_FLAG_CAPS_LOCK,
        _ => 0,   // ← Key::Function lands here → event dropped
    }
}

Fix

Map Key::Function to kCGEventFlagMaskSecondaryFn (0x800000), mirroring how the other modifiers are tracked:

const CGEVENT_FLAG_FUNCTION: u64 = 0x800000; // kCGEventFlagMaskSecondaryFn

fn flag_bit_for_key(key: Key) -> u64 {
    match key {
        // ...
        Key::CapsLock => CGEVENT_FLAG_CAPS_LOCK,
        Key::Function => CGEVENT_FLAG_FUNCTION,   // ← added
        _ => 0,
    }
}

Verification

Verified locally on macOS: pressing Fn now emits KeyDown(Function) / KeyUp(Function) events (previously nothing was emitted). Other modifiers are unaffected.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed handling of the Function (Fn) modifier on macOS, enabling correct press and release detection for Function key events.

v0.3.0 added Key::Function (kVK_Function, keycode 63) to the keycode table, but flag_bit_for_key() never got the matching branch, so every Fn FlagsChanged event fell through to the _ => 0 fallback arm and was silently dropped, making Fn unobservable on macOS. Map it to kCGEventFlagMaskSecondaryFn (0x800000), mirroring how the other modifiers are tracked.
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a956ba1f-07c9-4d58-aeb1-88b2c3cebc0f

📥 Commits

Reviewing files that changed from the base of the PR and between a1b3385 and 6fecb8b.

📒 Files selected for processing (1)
  • src/platform/macos/tap.rs

📝 Walkthrough

Walkthrough

Adds support for the macOS Fn (Function) modifier key in src/platform/macos/tap.rs. A new CGEVENT_FLAG_FUNCTION bit constant is defined, and flag_bit_for_key is extended to map Key::Function to that constant, enabling correct press/release edge detection for the Fn modifier.

Changes

Fn Modifier Recognition

Layer / File(s) Summary
Fn flag constant and key mapping
src/platform/macos/tap.rs
Defines CGEVENT_FLAG_FUNCTION as the CGEvent bit for the Fn modifier and adds Key::Function => CGEVENT_FLAG_FUNCTION to flag_bit_for_key, so FlagsChanged processing can classify Fn as a known modifier and emit synthesized key events.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 Hop hop, a tiny fix today,
The Fn key was lost, now found its way!
A constant defined, a mapping laid bare,
No more unknown modifier floating in air.
Two lines of Rust, the rabbit declares — done! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: adding Fn flag bit tracking in the FlagsChanged handler for macOS, which is the core fix in this pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant