Add desktop diagnostics and resilient message handling

This commit is contained in:
Misaka
2026-05-15 21:29:55 +08:00
parent 4c314c510b
commit d4b7a23e38
4 changed files with 71 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ public sealed class KeyboardInjectionService : IKeyboardInjectionService
return;
}
AppLogger.Info($"Injecting text length: {text.Length}");
foreach (var character in text)
{
SendUnicode(character);
@@ -25,11 +26,13 @@ public sealed class KeyboardInjectionService : IKeyboardInjectionService
public void Backspace()
{
AppLogger.Info("Injecting backspace.");
SendVirtualKey(VirtualKeyBack);
}
public void Enter()
{
AppLogger.Info("Injecting enter.");
SendVirtualKey(VirtualKeyReturn);
}
@@ -54,7 +57,9 @@ public sealed class KeyboardInjectionService : IKeyboardInjectionService
var sent = SendInput((uint)inputs.Length, inputs, Marshal.SizeOf<INPUT>());
if (sent != inputs.Length)
{
throw new InvalidOperationException("Windows did not accept all keyboard input events.");
var error = Marshal.GetLastWin32Error();
AppLogger.Error(
$"Windows accepted {sent}/{inputs.Length} keyboard input events. Win32 error: {error}");
}
}