From 2d749381e83ed3a1c6cf10512aceb5b1b8acf85a Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 2 May 2024 21:57:54 +0200 Subject: [PATCH] Fix AutoType not writing all text bug --- src/ClipCMD/MainWindow.xaml.cs | 13 ++++++++++--- src/ClipCMD/RuntimeData.cs | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ClipCMD/MainWindow.xaml.cs b/src/ClipCMD/MainWindow.xaml.cs index 76d4568..4652de3 100644 --- a/src/ClipCMD/MainWindow.xaml.cs +++ b/src/ClipCMD/MainWindow.xaml.cs @@ -126,7 +126,7 @@ public partial class MainWindow : Window parser.SetDelimiters(" "); - string[] sections = parser.ReadFields() ?? Array.Empty(); + string[] sections = parser.ReadFields() ?? []; sections = sections.Select(s => s.Replace('\0', '\"')).ToArray(); @@ -176,17 +176,24 @@ public partial class MainWindow : Window if (Settings.AutoPaste) { - _ = inputSimulator.Keyboard.ModifiedKeyStroke(new[] { VirtualKeyCode.CONTROL }, new[] { VirtualKeyCode.VK_V }); + _ = inputSimulator.Keyboard.ModifiedKeyStroke([VirtualKeyCode.CONTROL], [VirtualKeyCode.VK_V]); } } else if (Settings.Mode == ClipCMDMode.AutoType) { RuntimeData.AutoTypeRunning = true; + while (inputSimulator.InputDeviceState.IsKeyDown(VirtualKeyCode.CONTROL)) + { + // Wait for CTRL key to be released + await Task.Delay(100); + } + foreach (char c in outText.ToString()) { _ = inputSimulator.Keyboard.TextEntry(c); await Task.Delay(Settings.AutoTypeDelay); + if (!RuntimeData.AutoTypeRunning) { break; @@ -236,7 +243,7 @@ public partial class MainWindow : Window private void StaticCommandsTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { - string[] lines = RuntimeData.CommandsText.Split('\n').Append("[#END#]").ToArray(); + string[] lines = [.. RuntimeData.CommandsText.Split('\n'), "[#END#]"]; string commandNames = string.Empty; StringBuilder script = new StringBuilder(); diff --git a/src/ClipCMD/RuntimeData.cs b/src/ClipCMD/RuntimeData.cs index 87bd772..5e7deef 100644 --- a/src/ClipCMD/RuntimeData.cs +++ b/src/ClipCMD/RuntimeData.cs @@ -59,7 +59,7 @@ public class RuntimeData : INotifyPropertyChanged } } - public ObservableCollection Errors { get; } = new(); + public ObservableCollection Errors { get; } = []; public Visibility LogPanelVisible { @@ -71,7 +71,7 @@ public class RuntimeData : INotifyPropertyChanged } } - public ObservableCollection Logs { get; } = new(); + public ObservableCollection Logs { get; } = []; public RuntimeData() {