Skip to content

fix(v3): offer the Fn/Globe key to the input method on macOS - #6035

Open
taliesin-ai wants to merge 1 commit into
masterfrom
fix/v3-macos-fn-key-to-input-context
Open

fix(v3): offer the Fn/Globe key to the input method on macOS#6035
taliesin-ai wants to merge 1 commit into
masterfrom
fix/v3-macos-fn-key-to-input-context

Conversation

@taliesin-ai

@taliesin-ai taliesin-ai commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #6033pending confirmation from the reporter, see Testing.

The problem

The Fn/Globe key arrives as a modifier change, not a key press. WebKit drops keyCode 63 in WebViewImpl::flagsChanged() before it reaches interpretKeyEvent(), so the current input method never sees it. An input method that binds a shortcut to holding Fn — push-to-talk voice input is the common one, and hardware remappers produce the same event — does nothing at all inside a Wails window, while working in native and Chromium apps.

Nothing in Wails handled flagsChanged at all, so there was no existing code path to correct; this adds one.

The change

A local event monitor, alongside the two application_darwin.go already installs for mouse events, offers a keyCode 63 modifier change to the first responder's input context:

[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged handler:^NSEvent *(NSEvent *event) {
    if ([event keyCode] != kWailsFunctionKeyCode) { return event; }
    ...
    [inputContext handleEvent:event];
    return event;   // always
}];

The event is returned unchanged either way, so AppKit's own handling is untouched and no DOM keyboard event is synthesised — the page still doesn't see Fn, which is both the existing behaviour and the right one. The monitor ignores every other key code, and events belonging to windows that aren't ours.

This is the approach @1939869736luosi proposed in the issue, citing NSTextInputContext.handleEvent.

inputContext is declared on NSView, not NSResponder, and the first responder isn't necessarily a view — hence the isKindOfClass: check, which also keeps the cgo build free of warnings.

Testing

Verified: build and go vet clean, pkg/application tests pass, and sending real Fn presses to a running application changes nothing else — key bindings fire before and after, and nothing crashes. So the regression risk (swallowing events, or breaking normal keyboard handling) is covered.

Not verified: the symptom itself. Reproducing it needs an input method with a hold-Fn voice shortcut bound, which I don't have. Synthesising the event proves delivery, not that the input method acts on it.

@1939869736luosi — would you be able to build this branch and confirm your IME's Fn voice shortcut now works inside a Wails window? I'd rather not have this merged on the strength of reasoning alone.

Summary by CodeRabbit

  • New Features
    • Improved macOS keyboard handling for the Fn/Globe key in desktop windows.
    • Preserves text input behavior while preventing unintended web-based keyboard events.

The Fn/Globe key arrives as a modifier change rather than a key press, and
WebKit drops keyCode 63 in WebViewImpl::flagsChanged() before it reaches
interpretKeyEvent(). The current input method therefore never sees it, and
an input method that binds a shortcut to holding Fn - push-to-talk voice
input is the common one, and hardware remappers produce the same event -
does nothing at all inside a Wails window while working in native and
Chromium applications.

Nothing in Wails handled flagsChanged, so there was no code path to fix;
this adds one. A local event monitor, alongside the two this file already
installs for mouse events, offers a keyCode 63 modifier change to the first
responder's input context. The event is returned unchanged either way, so
AppKit's own handling is untouched and no DOM keyboard event is
synthesised - the page still does not see Fn, which is both the existing
behaviour and the right one.

The monitor ignores every other key code, and events belonging to windows
that are not ours.

Reported in #6033, which also proposed this approach and cited the
NSTextInputContext.handleEvent documentation for it.

Verified here: the build and vet are clean, the test suite passes, and
sending real Fn presses to a running application changes nothing else -
key bindings fire before and after, and the application does not crash.
What could not be verified here is the symptom itself, which needs an input
method with a hold-Fn voice shortcut bound. Synthesising the event proves
delivery, not that the input method acts on it, so the reporter should
confirm before this is trusted.

Claude-Session: https://claude.ai/code/session_01WP7MWnMpQDT2WB7CPLWbqr
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b14e0531-e806-4ae4-8693-75ce8c500533

📥 Commits

Reviewing files that changed from the base of the PR and between f609d2e and 8b06094.

📒 Files selected for processing (1)
  • v3/pkg/application/application_darwin.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The macOS application now monitors Fn/Globe modifier events with key code 63. Eligible Wails webview events are forwarded to the first responder’s text input context while the original event continues through AppKit.

Changes

Fn/Globe input forwarding

Layer / File(s) Summary
Monitor and input-context forwarding
v3/pkg/application/application_darwin.go
The Darwin application defines the Fn/Globe key code and forwards matching flagsChanged events from Wails webview windows to eligible first responders’ text input contexts. Other events remain unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 8b060

This localized macOS change forwards the Fn/Globe modifier to the input method while preserving AppKit’s original event handling. No actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant LocalMonitor
  participant WailsWebView
  participant FirstResponder
  participant NSTextInputContext
  LocalMonitor->>WailsWebView: Receive flagsChanged event
  WailsWebView->>FirstResponder: Resolve first responder
  FirstResponder->>NSTextInputContext: Forward Fn/Globe event
  NSTextInputContext-->>LocalMonitor: Process event
  LocalMonitor-->>WailsWebView: Return original event
Loading

Suggested reviewers: leaanthony, julianstorer

Poem

A rabbit watched the Globe key glow

Through WebKit’s quiet flow
The input context heard the call
While AppKit kept the event for all
Fn now hops where IMEs know

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation addresses issue #6033 by monitoring Fn/Globe flags-changed events, forwarding keyCode 63 to the first responder input context, preserving the original event, excluding other key cod…
Out of Scope Changes check ✅ Passed The changes are limited to macOS Fn/Globe event handling and directly support the requirements in issue #6033. No unrelated code changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Title check ✅ Passed The title clearly and concisely describes the main change: forwarding the macOS Fn/Globe key to the input method.
Description check ✅ Passed The description provides the issue context, implementation details, testing results, and remaining validation status. It does not complete the template checkboxes or include wails doctor output, but…
Full details: Linked Issues check

Explanation

The implementation addresses issue #6033 by monitoring Fn/Globe flags-changed events, forwarding keyCode 63 to the first responder input context, preserving the original event, excluding other key codes and non-Wails windows, and avoiding DOM keyboard events.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

Full details: Description check

Explanation

The description provides the issue context, implementation details, testing results, and remaining validation status. It does not complete the template checkboxes or include wails doctor output, but the core information is present and relevant.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/v3-macos-fn-key-to-input-context

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: Fn/Globe key (keyCode 63) swallowed by WKWebView before reaching IME — IME voice shortcuts fail in Wails apps

1 participant