From dc92447e5fa1fa4b345d7138e6bd54296dd3c937 Mon Sep 17 00:00:00 2001 From: Ilia Burakov Date: Sun, 23 Nov 2025 21:21:06 -0500 Subject: [PATCH 1/2] Logs result of SendInput calls Adds logging to track the number of input events successfully sent by SendInput. This helps diagnose potential issues where not all input events are processed correctly. It logs an error if the number of sent events doesn't match the expected count and a trace if all events are successfully sent. --- WinSyncScroll/ViewModels/MainViewModel.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/WinSyncScroll/ViewModels/MainViewModel.cs b/WinSyncScroll/ViewModels/MainViewModel.cs index 63fcc9d..5c87fd7 100644 --- a/WinSyncScroll/ViewModels/MainViewModel.cs +++ b/WinSyncScroll/ViewModels/MainViewModel.cs @@ -343,7 +343,20 @@ private async Task RunMouseEventProcessingLoopAsync( if (!_options.Value.IsLegacyModeEnabled) { LogSendInput(inputs); - PInvoke.SendInput(inputs.AsSpan(), SizeOfInput); + var sentCount = PInvoke.SendInput(inputs.AsSpan(), SizeOfInput); + + if (sentCount != inputs.Length) + { + var lastError = Marshal.GetLastWin32Error(); + _logger.LogError("SendInput failed: expected to send {ExpectedCount} events, but only {SentCount} were sent. Last Win32 error: {LastError}", + inputs.Length, + sentCount, + lastError); + } + else + { + _logger.LogTrace("Successfully sent {SentCount} input events", sentCount); + } } else { From 04c93f2bad501eb33ae24f4ba9533e40bc5fbbbd Mon Sep 17 00:00:00 2001 From: Ilia Burakov Date: Sun, 23 Nov 2025 21:30:59 -0500 Subject: [PATCH 2/2] Logs PostMessage results Adds logging to record the success or failure of PostMessage calls. Logs the last Win32 error when PostMessage fails, aiding in debugging. Logs successful message posts for tracing purposes. --- WinSyncScroll/ViewModels/MainViewModel.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/WinSyncScroll/ViewModels/MainViewModel.cs b/WinSyncScroll/ViewModels/MainViewModel.cs index 5c87fd7..78f0180 100644 --- a/WinSyncScroll/ViewModels/MainViewModel.cs +++ b/WinSyncScroll/ViewModels/MainViewModel.cs @@ -382,7 +382,20 @@ private async Task RunMouseEventProcessingLoopAsync( lParam, targetX, targetY); - PInvoke.PostMessage(windowHandle, (uint)buffer.MouseMessageId, (nuint)buffer.MouseMessageData.mouseData, lParam); + + var result = PInvoke.PostMessage(windowHandle, (uint)buffer.MouseMessageId, (nuint)buffer.MouseMessageData.mouseData, lParam); + + if (!result) + { + var lastError = Marshal.GetLastWin32Error(); + _logger.LogError("PostMessage failed for window {WindowHandle}: Last Win32 error: {LastError}", + windowHandle, + lastError); + } + else + { + _logger.LogTrace("Successfully posted message to window {WindowHandle}", windowHandle); + } } } }