protected void HandleKeystroke() { if (string.IsNullOrEmpty(settings.Command)) { return; } if (settings.Command.Length == 1) // 1 Character is fine { return; } var macro = CommandTools.ExtractMacro(settings.Command, 0); if (string.IsNullOrEmpty(macro)) // Not a macro, save only first character { settings.Command = settings.Command[0].ToString(); SaveSettings(); } else { if (settings.Command != macro) // Save only one keystroke { settings.Command = macro; SaveSettings(); } } }
protected async void SendInput(string inputText) { InputRunning = true; await Task.Run(() => { var text = inputText; for (var idx = 0; idx < text.Length && !ForceStop; idx++) { var macro = CommandTools.ExtractMacro(text, idx); idx += macro.Length - 1; macro = macro.Substring(1, macro.Length - 2); HandleMacro(macro); } }); InputRunning = false; }
private void HandleMacro(string macro) { var keyStrokes = CommandTools.ExtractKeyStrokes(macro); // Actually initiate the keystrokes if (keyStrokes.Count > 0) { var iis = new InputSimulator(); var keyCode = keyStrokes.Last(); keyStrokes.Remove(keyCode); if (keyStrokes.Count > 0) { iis.Keyboard.ModifiedKeyStroke(keyStrokes.Select(ks => ks).ToArray(), keyCode); } else // Single Keycode { iis.Keyboard.KeyPress(keyCode); } } }
protected void RunCommand() { try { if (string.IsNullOrEmpty(settings.Command)) { Logger.Instance.LogMessage(TracingLevel.WARN, "Command not configured"); return; } if (settings.Command.Length == 1) { Task.Run(() => SimulateTextEntry(settings.Command[0])); } else // KeyStroke { var keyStrokes = CommandTools.ExtractKeyStrokes(settings.Command); // Actually initiate the keystrokes if (keyStrokes.Count > 0) { var keyCode = keyStrokes.Last(); keyStrokes.Remove(keyCode); if (keyStrokes.Count > 0) { Task.Run(() => SimulateKeyStroke(keyStrokes.Select(ks => ks).ToArray(), keyCode)); } else { Task.Run(() => SimulateKeyDown(keyCode)); } } } } catch (Exception ex) { Logger.Instance.LogMessage(TracingLevel.FATAL, $"RunCommand Exception: {ex}"); } }