Paste submitted text to preserve punctuation
This commit is contained in:
@@ -10,6 +10,7 @@ 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)
|
||||||
@@ -20,12 +21,45 @@ 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)
|
||||||
{
|
{
|
||||||
SendUnicode(character);
|
SendUnicode(character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ReplaceFocusedText(string text)
|
public void ReplaceFocusedText(string text)
|
||||||
{
|
{
|
||||||
AppLogger.Info($"Replacing focused text length: {text.Length}");
|
AppLogger.Info($"Replacing focused text length: {text.Length}");
|
||||||
|
|||||||
Reference in New Issue
Block a user