Add desktop diagnostics and resilient message handling
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user