Clear modifier flags on synthetic Enter on macOS#131
Merged
Conversation
When auto-submitting a snippet with Cmd+Enter, the preceding synthetic Cmd+V events left Cmd latched in the HID session state, so the Return event that followed inherited the Cmd flag. Targets like Edge then saw Cmd+Enter and opened a new tab instead of just submitting. Explicitly set flags to 0 on both the keyDown and keyUp Return events so the synthetic Enter is delivered as plain Enter regardless of any stale or still-held Cmd state. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes macOS auto-submit behavior so that the synthetic “Enter” sent after a Cmd+V paste is delivered as a plain Return keypress (not Cmd+Enter), preventing target apps (e.g., Edge) from treating it as a command-modified action.
Changes:
- Clear CoreGraphics modifier flags on the synthetic Return keyDown/keyUp events in
MacOSApplication.SendEnterShortcut.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
When auto-submitting a snippet with Cmd+Enter on macOS, the target app (e.g., Edge) would often see Cmd+Enter instead of plain Enter — for example, pasting a URL snippet into the address bar would open a new tab rather than just navigate in the current one.
Cause
MacOSApplication.SendEnterShortcutcreated the ReturnCGEventwithout ever callingCGEventSetFlags. The event source (kCGEventSourceStateHIDSystemState) inherits the current modifier state, and the preceding synthetic Cmd+V posted both keyDown and keyUp forVwith the Cmd flag set, which leaves Cmd latched in the session state. The Return event then went out carrying Cmd.Fix
Explicitly set
flags = 0on both the keyDown and keyUp Return events inSendEnterShortcut, so the synthetic Enter is delivered as a plain Enter regardless of any stale Cmd state from the paste or a physically still-held Cmd key.Note: I also considered re-awaiting
WaitForAutoSubmitModifierReleaseAsync()right beforeSimulateEnter, but that ended up waiting indefinitely (or until the user physically tapped Cmd again) because our own Cmd+V injection keeps Cmd reported as pressed in the combined session state. Clearing the flags on the Return event itself is the right layer to solve this.