Skip to content

Fix SendKeys sequential immediate modifier(^a^c, +a+c, %f%t) parsing regression - #14691

Merged
LeafShi1 merged 2 commits into
dotnet:mainfrom
LeafShi1:Fix_14690_SendKeys_parsing_regression
Jul 8, 2026
Merged

Fix SendKeys sequential immediate modifier(^a^c, +a+c, %f%t) parsing regression#14691
LeafShi1 merged 2 commits into
dotnet:mainfrom
LeafShi1:Fix_14690_SendKeys_parsing_regression

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Jul 1, 2026

Copy link
Copy Markdown
Member

Fixes #14690

Root Cause

In PR #3621, int[] haveKeys (a reference type with implicit by-reference semantics) was refactored to a value tuple. Without adding ref, the modifier state mutations inside AddSimpleKey were silently lost, breaking sequential immediate modifier sequences.

Proposed changes

  • Pass modifier state by reference when calling AddSimpleKey, so cancellation updates are preserved in ParseKeys state.
  • Update AddSimpleKey signature to accept modifier tuple by ref.
  • Add regression unit tests for sequential immediate modifier patterns:^a^c, +a+c, %f%t

Customer Impact

  • Apps migrated from .NET Framework that use sequential immediate modifier sequences in SendKeys (e.g. ^a^c) will no longer throw an unexpected

Regression?

  • Yes

Risk

  • Minimal

Screenshots

Sample project WinFormsApp8.zip

Before

System.ArgumentException: SendKeys string "^a^c" is not valid.

image

After

^a^c was parsed as Ctrl+A followed by Ctrl+C, consistent with .NET Framework behavior.

image

Test methodology

  • Manually and unit test

Test environment(s)

  • .net 11.0.0-preview.7.26330.112
Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in System.Windows.Forms.SendKeys parsing where sequential immediate modifier sequences (e.g. ^a^c, +a+c, %f%t) incorrectly throw ArgumentException on modern .NET, restoring behavior consistent with .NET Framework.

Changes:

  • Passes the modifier-state tuple by ref into AddSimpleKey so modifier cancellation updates persist in ParseKeys.
  • Updates AddSimpleKey signature and call sites to use ref haveKeys.
  • Adds a regression unit test covering sequential immediate modifier patterns.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/test/unit/System.Windows.Forms/System/Windows/Forms/SendKeysTests.cs Adds regression coverage for sequential immediate modifier parsing.
src/System.Windows.Forms/System/Windows/Forms/SendKeys/SendKeys.cs Fixes modifier-state propagation by passing the tuple by ref.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@KlausLoeffelmann KlausLoeffelmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! :shipit:

@LeafShi1
LeafShi1 merged commit d1b3176 into dotnet:main Jul 8, 2026
8 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 11, 2026
@LeafShi1 LeafShi1 added the releasenotes-candidate This issue is a candidate to be mentioned in the release notes, if the respective PR fixed it. label Jul 15, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

releasenotes-candidate This issue is a candidate to be mentioned in the release notes, if the respective PR fixed it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SendKeys.ParseKeys rejects "^a^c" on .NET 10 although it works on .NET Framework

4 participants