Skip to content

Comments

Replace PInvoke.User32 with Microsoft.Windows.CsWin32 source generator#318

Merged
Keboo merged 3 commits intomasterfrom
copilot/remove-pinvoke-user32-package
Feb 6, 2026
Merged

Replace PInvoke.User32 with Microsoft.Windows.CsWin32 source generator#318
Keboo merged 3 commits intomasterfrom
copilot/remove-pinvoke-user32-package

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

Remove the PInvoke.User32 NuGet package dependency and migrate all call sites to the Microsoft.Windows.CsWin32 source generator that was already partially adopted in the project.

Win32 API declarations

Added to XAMLTest/NativeMethods.txt: mouse_event, SetCursorPos, GetCursorPos, SendMessage, SendInput, GetAsyncKeyState, GetForegroundWindow, GetParent, GetWindowPlacement

Created XAMLTest.Tests/NativeMethods.txt with GetWindowPlacement for test project usage.

Type mapping

  • mouse_eventFlagsMOUSE_EVENT_FLAGS
  • VirtualKeyVIRTUAL_KEY
  • KEYEVENTFKEYBD_EVENT_FLAGS
  • User32.InputTypeINPUT_TYPE
  • input.Inputs.kiinput.Anonymous.ki
  • User32.WindowMessage.*uint constants (WM_CHAR, WM_KEYDOWN, WM_KEYUP)
  • IntPtr window handles → HWND (in VisualTreeService.cs)
  • WindowShowStyleSHOW_WINDOW_CMD

Package references

  • Removed PInvoke.User32 from XAMLTest.csproj and Directory.Packages.props
  • Added Microsoft.Windows.CsWin32 to XAMLTest.Tests.csproj

Example: KeyboardInput.cs before/after

// Before
input.Inputs.ki.wVk = modifierKey;
input.Inputs.ki.dwFlags = KEYEVENTF.KEYEVENTF_KEYUP;
User32.SendInput(1, new[] { input.Input }, sizeOfInputStruct);

// After
input.Anonymous.ki.wVk = modifierKey;
input.Anonymous.ki.dwFlags = KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP;
PInvoke.SendInput([input.Input], sizeOfInputStruct);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Remove PInvoke.User32 and replace with Microsoft.Windows.CsWin32 Replace PInvoke.User32 with Microsoft.Windows.CsWin32 source generator Feb 6, 2026
Copilot AI requested a review from Keboo February 6, 2026 05:51
@Keboo Keboo marked this pull request as ready for review February 6, 2026 06:08
@Keboo Keboo enabled auto-merge (squash) February 6, 2026 06:09
Copilot AI and others added 3 commits February 5, 2026 22:12
Co-authored-by: Keboo <952248+Keboo@users.noreply.github.com>
Co-authored-by: Keboo <952248+Keboo@users.noreply.github.com>
@Keboo Keboo force-pushed the copilot/remove-pinvoke-user32-package branch from b033362 to 20e65b5 Compare February 6, 2026 06:13
@Keboo Keboo merged commit 057d709 into master Feb 6, 2026
3 checks passed
@Keboo Keboo deleted the copilot/remove-pinvoke-user32-package branch February 6, 2026 06:18
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.

2 participants