Revert clipboard input path
This commit is contained in:
@@ -10,7 +10,6 @@ public sealed class KeyboardInjectionService : IKeyboardInjectionService
|
|||||||
private const ushort VirtualKeyA = 0x41;
|
private const ushort VirtualKeyA = 0x41;
|
||||||
private const ushort VirtualKeyBack = 0x08;
|
private const ushort VirtualKeyBack = 0x08;
|
||||||
private const ushort VirtualKeyControl = 0x11;
|
private const ushort VirtualKeyControl = 0x11;
|
||||||
private const ushort VirtualKeyV = 0x56;
|
|
||||||
private const ushort VirtualKeyReturn = 0x0D;
|
private const ushort VirtualKeyReturn = 0x0D;
|
||||||
|
|
||||||
public void InsertText(string text)
|
public void InsertText(string text)
|
||||||
@@ -21,42 +20,11 @@ public sealed class KeyboardInjectionService : IKeyboardInjectionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
AppLogger.Info($"Injecting text length: {text.Length}");
|
AppLogger.Info($"Injecting text length: {text.Length}");
|
||||||
PasteText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TypeText(string text)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(text))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var character in text)
|
foreach (var character in text)
|
||||||
{
|
{
|
||||||
|
AppLogger.Info($"Injecting char U+{(int)character:X4}: {character}");
|
||||||
SendUnicode(character);
|
SendUnicode(character);
|
||||||
}
|
Thread.Sleep(2);
|
||||||
}
|
|
||||||
|
|
||||||
private static void PasteText(string text)
|
|
||||||
{
|
|
||||||
var hadText = Clipboard.ContainsText();
|
|
||||||
var previousText = hadText ? Clipboard.GetText() : null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Clipboard.SetText(text);
|
|
||||||
SendModifiedKey(VirtualKeyControl, VirtualKeyV);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (hadText && previousText is not null)
|
|
||||||
{
|
|
||||||
Clipboard.SetText(previousText);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Clipboard.Clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user