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 { List <VirtualKeyCodeContainer> keyStrokes = CommandTools.ExtractKeyStrokes(settings.Command); // Actually initiate the keystrokes if (keyStrokes.Count > 0) { VirtualKeyCodeContainer keyCode = keyStrokes.Last(); keyStrokes.Remove(keyCode); if (keyStrokes.Count > 0) { Task.Run(() => SimulateKeyStroke(keyStrokes.Select(ks => ks.KeyCode).ToArray(), keyCode.KeyCode)); } else { if (keyCode.IsExtended) { Task.Run(() => SimulateExtendedMacro(keyCode)); } else { Task.Run(() => SimulateKeyDown(keyCode.KeyCode)); } } } } } catch (Exception ex) { Logger.Instance.LogMessage(TracingLevel.ERROR, $"RunCommand Exception: {ex}"); } }
protected void HandleMacro(string macro) { List <VirtualKeyCodeContainer> keyStrokes = CommandTools.ExtractKeyStrokes(macro); // Actually initiate the keystrokes if (keyStrokes.Count > 0) { InputSimulator iis = new InputSimulator(); VirtualKeyCodeContainer keyCode = keyStrokes.Last(); keyStrokes.Remove(keyCode); if (keyStrokes.Count > 0) { if (settings.KeydownDelay) { Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} DelayedModifiedKeyStroke"); iis.Keyboard.DelayedModifiedKeyStroke(keyStrokes.Select(ks => ks.KeyCode).ToArray(), new VirtualKeyCode[] { keyCode.KeyCode }, settings.Delay); } else { Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} ModifiedKeyStroke"); iis.Keyboard.ModifiedKeyStroke(keyStrokes.Select(ks => ks.KeyCode).ToArray(), keyCode.KeyCode); } } else // Single Keycode { if (keyCode.IsExtended) { Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} HandleExtendedMacro"); ExtendedMacroHandler.HandleExtendedMacro(iis, keyCode); } else // Normal single keycode { if (!MouseHandler.HandleMouseMacro(iis, keyCode.KeyCode)) { Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} KeyPress"); iis.Keyboard.KeyPress(keyCode.KeyCode); } } } } }