private static void HandleKeyboardCommand(InputSimulator iis, VirtualKeyCodeContainer macro)
        {
            string commandText = CommandTools.ConvertSimilarMacroCommands(macro.ExtendedData.ToUpperInvariant());

            if (string.IsNullOrEmpty(commandText))
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"Extended Keydown/Keyup - Missing Command");
                return;
            }

            if (!Enum.TryParse <VirtualKeyCode>(commandText, true, out VirtualKeyCode code))
            {
                if (commandText.Length > 1)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Extended Keydown/Keyup Shrinking {commandText} to {commandText[0]}");
                }
                code = (VirtualKeyCode)commandText[0];
            }

            if (macro.ExtendedCommand == EXTENDED_COMMANDS_LIST[(int)ExtendedCommand.EXTENDED_MACRO_KEY_DOWN])
            {
                RepeatKeyDown(iis, code);
                //iis.Keyboard.KeyDown(code);
            }
            else
            {
                dicRepeatKeydown[code] = false;
                //iis.Keyboard.KeyUp(code);
            }
        }
Пример #2
0
        internal static List <VirtualKeyCodeContainer> ExtractKeyStrokes(string macroText)
        {
            List <VirtualKeyCodeContainer> keyStrokes = new List <VirtualKeyCodeContainer>();


            try
            {
                MatchCollection matches = Regex.Matches(macroText, CommandTools.REGEX_SUB_COMMAND);
                foreach (var match in matches)
                {
                    string matchText = match.ToString().Replace("{", "").Replace("}", "");
                    if (matchText.Length == 1)
                    {
                        char code = matchText.ToUpperInvariant()[0];
                        keyStrokes.Add(new VirtualKeyCodeContainer((VirtualKeyCode)code));
                    }
                    else
                    {
                        VirtualKeyCodeContainer stroke = CommandTools.MacroTextToKeyCode(matchText);
                        if (stroke != null)
                        {
                            keyStrokes.Add(stroke);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"ExtractKeyStrokes Exception: {ex}");
            }

            return(keyStrokes);
        }
        public static void HandleExtendedMacro(InputSimulator iis, VirtualKeyCodeContainer macro)
        {
            try
            {
                // Index in array
                int             index   = EXTENDED_COMMANDS_LIST.ToList().FindIndex(cmd => cmd == macro.ExtendedCommand);
                ExtendedCommand command = (ExtendedCommand)index;


                // Check if it's a pause command
                if (command == ExtendedCommand.EXTENDED_MACRO_PAUSE)
                {
                    if (Int32.TryParse(macro.ExtendedData, out int pauseLength))
                    {
                        Thread.Sleep(pauseLength);
                        return;
                    }
                }
                // Keyboard commands
                else if (command == ExtendedCommand.EXTENDED_MACRO_KEY_DOWN || command == ExtendedCommand.EXTENDED_MACRO_KEY_UP)
                {
                    HandleKeyboardCommand(command, iis, macro);
                    return;
                }
                // Mouse commands
                else if (index >= (int)ExtendedCommand.EXTENDED_MACRO_MOUSE_MOVE && index <= (int)ExtendedCommand.EXTENDED_MACRO_MOUSE_RESTORE_LOCATION)
                {
                    HandleMouseCommand(command, iis, macro);
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_INPUT || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT ||
                         command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSETALL || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSET ||
                         command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE)
                {
                    HandleVariableCommand(command, iis, macro);
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleExtendedMacro - Invalid command {command}");
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"Failed to parse extended macro: {macro?.ExtendedCommand} {macro?.ExtendedData} {ex}");
            }
        }
Пример #4
0
        protected void HandleMacro(string macro, WriterSettings settings, SetKeyTitle setKeyTitleFunction)
        {
            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, settings, setKeyTitleFunction);
                    }
                    else // Normal single keycode
                    {
                        if (!MouseHandler.HandleMouseMacro(iis, keyCode.KeyCode))
                        {
                            Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} KeyPress");
                            iis.Keyboard.KeyPress(keyCode.KeyCode);
                        }
                    }
                }
            }
        }
        private static async Task HandleVariableCommand(ExtendedCommand command, VirtualKeyCodeContainer macro, WriterSettings settings)
        {
            string upperExtendedData = macro.ExtendedData.ToUpperInvariant();

            // Variables
            if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_INPUT)
            {
                string defaultValue = String.Empty;
                if (!String.IsNullOrEmpty(upperExtendedData) && dicVariables.ContainsKey(upperExtendedData))
                {
                    defaultValue = dicVariables[upperExtendedData];
                }

                using InputBox input = new InputBox("Variable Input", $"Enter value for \"{upperExtendedData}\":", defaultValue);
                input.ShowDialog();

                // Value exists (cancel button was NOT pressed)
                if (!string.IsNullOrEmpty(input.Input))
                {
                    dicVariables[upperExtendedData] = input.Input;
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT)
            {
                if (dicVariables.ContainsKey(upperExtendedData))
                {
                    SuperMacroWriter textWriter = new SuperMacroWriter();
                    await textWriter.SendInput(dicVariables[upperExtendedData], settings, null, false);
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Output called for {upperExtendedData} without an Input beforehand");
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSETALL)
            {
                dicVariables.Clear();
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSET)
            {
                if (string.IsNullOrEmpty(upperExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Unset called without variable name");
                    return;
                }
                if (dicVariables.ContainsKey(upperExtendedData))
                {
                    dicVariables.Remove(upperExtendedData);
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE)
            {
                if (string.IsNullOrEmpty(macro.ExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Set called without variable name");
                    return;
                }

                // last parameter "2" ensures maximum of two splits!
                var splitData = macro.ExtendedData.Split(new char[] { ':' }, 2);
                if (splitData.Length != 2)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Set called without incorrect extended data: {macro.ExtendedData}");
                    return;
                }
                string varInput = splitData[1];
                string fileName = TryExtractVariable(splitData[1]);

                // Set From File but file doesn't exist
                if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE && !File.Exists(fileName))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable SetFromFile called but file does not exist {fileName}");
                    return;
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE) // File DOES exist
                {
                    varInput = File.ReadAllText(fileName);
                }

                dicVariables[splitData[0].ToUpperInvariant()] = varInput;
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_CLIPBOARD)
            {
                var value = ReadFromClipboard();

                // Value exists (cancel button was NOT pressed)
                if (!string.IsNullOrEmpty(value))
                {
                    dicVariables[upperExtendedData] = value;
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT_TO_FILE)
            {
                if (string.IsNullOrEmpty(macro.ExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile called without any params");
                    return;
                }

                var splitData = macro.ExtendedData.Split(new char[] { ':' }, 2);
                if (splitData.Length != 2)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile called without incorrect extended data: {macro.ExtendedData}");
                    return;
                }

                string variableName = splitData[0].ToUpperInvariant();
                string fileName     = TryExtractVariable(splitData[1]);

                // Check if variable exists
                if (!dicVariables.ContainsKey(variableName))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile called without non existing variable: {variableName}");
                    return;
                }

                // Try to save the data in the variable to the filename
                try
                {
                    File.WriteAllText(fileName, dicVariables[variableName]);
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile exception: {macro.ExtendedData} {ex}");
                }
                return;
            }
            else
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleVariableCommand - Invalid command {command}");
            }
        }
 private static void HandleMouseScrollCommand(ExtendedCommand command, InputSimulator iis, VirtualKeyCodeContainer macro)
 {
     // Scroll UP/DOWN/LEFT/RIGHT
     if (command == ExtendedCommand.EXTENDED_MACRO_SCROLL_UP || command == ExtendedCommand.EXTENDED_MACRO_SCROLL_DOWN)
     {
         int direction = (command == ExtendedCommand.EXTENDED_MACRO_SCROLL_UP) ? 1 : -1;
         if (Int32.TryParse(macro.ExtendedData, out int mouseClicks) && mouseClicks > 0)
         {
             direction *= mouseClicks;
         }
         iis.Mouse.VerticalScroll(direction);
     }
     else if (command == ExtendedCommand.EXTENDED_MACRO_SCROLL_LEFT || command == ExtendedCommand.EXTENDED_MACRO_SCROLL_RIGHT)
     {
         int direction = (macro.ExtendedCommand == EXTENDED_COMMANDS_LIST[(int)ExtendedCommand.EXTENDED_MACRO_SCROLL_RIGHT]) ? 1 : -1;
         if (Int32.TryParse(macro.ExtendedData, out int mouseClicks) && mouseClicks > 0)
         {
             direction *= mouseClicks;
         }
         iis.Mouse.HorizontalScroll(direction);
     }
     else
     {
         Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleMouseScrollCommand - Invalid command {command}");
     }
 }
        private static void HandleMouseMoveCommand(ExtendedCommand command, InputSimulator iis, VirtualKeyCodeContainer macro)
        {
            if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_MOVE || command == ExtendedCommand.EXTENDED_MACRO_MOUSE_POS ||
                command == ExtendedCommand.EXTENDED_MACRO_MOUSE_XY)  // Mouse Move
            {
                string[] mousePos = macro.ExtendedData.Split(',');
                if (mousePos.Length != 2)
                {
                    mousePos = macro.ExtendedData.Split(':');
                }
                if (mousePos.Length == 2)
                {
                    string mouseX = TryExtractVariable(mousePos[0]);
                    string mouseY = TryExtractVariable(mousePos[1]);

                    if (Double.TryParse(mouseX, out double x) && Double.TryParse(mouseY, out double y))
                    {
                        if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_POS)
                        {
                            iis.Mouse.MoveMouseToPositionOnVirtualDesktop(x, y);
                        }
                        else if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_XY)
                        {
                            System.Windows.Forms.Cursor.Position = new Point((int)x, (int)y);
                        }
                        else
                        {
                            iis.Mouse.MoveMouseBy((int)x, (int)y);
                        }
                    }
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleMouseMoveCommand - Invalid parameter {macro.ExtendedData}");
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_STORE_LOCATION) // Mouse Store
            {
                Point point = System.Windows.Forms.Cursor.Position;
                dicVariables[MOUSE_STORED_X_VARIABLE] = point.X.ToString();
                dicVariables[MOUSE_STORED_Y_VARIABLE] = point.Y.ToString();
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_RESTORE_LOCATION) // Mouse Restore
            {
                if (!dicVariables.ContainsKey(MOUSE_STORED_X_VARIABLE) || !dicVariables.ContainsKey(MOUSE_STORED_Y_VARIABLE))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Restore Mouse called but no variables assigned");
                    return;
                }


                int.TryParse(dicVariables[MOUSE_STORED_X_VARIABLE], out int mouseX);
                int.TryParse(dicVariables[MOUSE_STORED_Y_VARIABLE], out int mouseY);
                System.Windows.Forms.Cursor.Position = new Point(mouseX, mouseY);
            }
            else
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleMouseMoveCommand - Invalid command {command}");
            }
            return;
        }
 private static void HandleMouseCommand(ExtendedCommand command, InputSimulator iis, VirtualKeyCodeContainer macro)
 {
     // Mouse Move commands
     if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_MOVE || command == ExtendedCommand.EXTENDED_MACRO_MOUSE_POS ||
         command == ExtendedCommand.EXTENDED_MACRO_MOUSE_XY ||
         command == ExtendedCommand.EXTENDED_MACRO_MOUSE_STORE_LOCATION || command == ExtendedCommand.EXTENDED_MACRO_MOUSE_RESTORE_LOCATION)
     {
         HandleMouseMoveCommand(command, iis, macro);
     }
     else if (command == ExtendedCommand.EXTENDED_MACRO_SCROLL_UP || command == ExtendedCommand.EXTENDED_MACRO_SCROLL_DOWN || command == ExtendedCommand.EXTENDED_MACRO_SCROLL_LEFT ||
              command == ExtendedCommand.EXTENDED_MACRO_SCROLL_RIGHT)
     {
         HandleMouseScrollCommand(command, iis, macro);
     }
     else if (command == ExtendedCommand.EXTENDED_MACRO_MOUSE_LEFT_DOWN ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_LEFT_UP ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_RIGHT_DOWN ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_RIGHT_UP ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_MIDDLE_DOWN ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_MIDDLE_UP ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_LEFT_DOUBLE_CLICK ||
              command == ExtendedCommand.EXTENDED_MACRO_MOUSE_RIGHT_DOUBLE_CLICK)
     {
         HandleMouseButtonCommand(command, iis);
     }
     else
     {
         Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleMouseCommand - Invalid command {command}");
     }
 }
        public static async Task HandleExtendedMacro(InputSimulator iis, VirtualKeyCodeContainer macro, WriterSettings settings, SetKeyTitle SetKeyTitleFunction)
        {
            try
            {
                // Index in array
                int             index   = EXTENDED_COMMANDS_LIST.ToList().FindIndex(cmd => cmd == macro.ExtendedCommand);
                ExtendedCommand command = (ExtendedCommand)index;

                // Check if this is a function command
                if (command == ExtendedCommand.EXTENDED_MACRO_FUNCTIONS)
                {
                    FunctionsHandler.HandleFunctionRequest(macro.ExtendedData, dicVariables);
                }
                // Check if it's a pause command
                else if (command == ExtendedCommand.EXTENDED_MACRO_PAUSE)
                {
                    string pauseLengthParam = TryExtractVariable(macro.ExtendedData);
                    if (Int32.TryParse(pauseLengthParam, out int pauseLength))
                    {
                        Thread.Sleep(pauseLength);
                        return;
                    }
                }
                // Keyboard commands
                else if (command == ExtendedCommand.EXTENDED_MACRO_KEY_DOWN || command == ExtendedCommand.EXTENDED_MACRO_KEY_UP)
                {
                    HandleKeyboardCommand(iis, macro);
                    return;
                }
                // Mouse commands
                else if (index >= (int)ExtendedCommand.EXTENDED_MACRO_MOUSE_MOVE && index <= (int)ExtendedCommand.EXTENDED_MACRO_MOUSE_RESTORE_LOCATION)
                {
                    HandleMouseCommand(command, iis, macro);
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_INPUT || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT ||
                         command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSETALL || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSET ||
                         command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE ||
                         command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_CLIPBOARD || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT_TO_FILE)
                {
                    await HandleVariableCommand(command, macro, settings);
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_STREAMDECK_SETKEYTITLE)
                {
                    if (SetKeyTitleFunction == null)
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, $"SETKEYTITLE called but callback function is null");
                        return;
                    }
                    string titleString = TryExtractVariable(macro.ExtendedData).Replace(@"\n", "\n");
                    SetKeyTitleFunction(titleString);
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_STREAMDECK_SETCLIPBOARD)
                {
                    SetClipboard(TryExtractVariable(macro.ExtendedData));
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleExtendedMacro - Invalid command {command}");
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"Failed to parse extended macro: {macro?.ExtendedCommand} {macro?.ExtendedData} {ex}");
            }
        }
        private static void HandleVariableCommand(ExtendedCommand command, InputSimulator iis, VirtualKeyCodeContainer macro)
        {
            string upperExtendedData = macro.ExtendedData.ToUpperInvariant();

            // Variables
            if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_INPUT)
            {
                using InputBox input = new InputBox("Variable Input", $"Enter value for \"{upperExtendedData}\":");
                input.ShowDialog();

                // Value exists (cancel button was NOT pressed)
                if (!string.IsNullOrEmpty(input.Input))
                {
                    dicVariables[upperExtendedData] = input.Input;
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT)
            {
                if (dicVariables.ContainsKey(upperExtendedData))
                {
                    iis.Keyboard.TextEntry(dicVariables[upperExtendedData]);
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Output called for {upperExtendedData} without an Input beforehand");
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSETALL)
            {
                dicVariables.Clear();
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSET)
            {
                if (string.IsNullOrEmpty(upperExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Unset called without variable name");
                    return;
                }
                if (dicVariables.ContainsKey(upperExtendedData))
                {
                    dicVariables.Remove(upperExtendedData);
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE)
            {
                if (string.IsNullOrEmpty(macro.ExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Set called without variable name");
                    return;
                }

                var splitData = macro.ExtendedData.Split(new char[] { ':' }, 2);
                if (splitData.Length != 2)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Set called without incorrect extended data: {macro.ExtendedData}");
                    return;
                }
                string varInput = splitData[1];

                // Set From File but file doesn't exist
                if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE && !File.Exists(splitData[1]))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable SetFromFile called but file does not exist {splitData[1]}");
                    return;
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE) // File DOES exist
                {
                    varInput = File.ReadAllText(splitData[1]);
                }

                dicVariables[splitData[0].ToUpperInvariant()] = varInput;
            }
            else
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleVariableCommand - Invalid command {command}");
            }
        }
Пример #11
0
        private static void HandleVariableCommand(ExtendedCommand command, InputSimulator iis, VirtualKeyCodeContainer macro, WriterSettings settings, SDConnection connection)
        {
            string upperExtendedData = macro.ExtendedData.ToUpperInvariant();

            // Variables
            if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_INPUT)
            {
                string defaultValue = String.Empty;
                if (!String.IsNullOrEmpty(upperExtendedData) && dicVariables.ContainsKey(upperExtendedData))
                {
                    defaultValue = dicVariables[upperExtendedData];
                }

                using InputBox input = new InputBox("Variable Input", $"Enter value for \"{upperExtendedData}\":", defaultValue);
                input.ShowDialog();

                // Value exists (cancel button was NOT pressed)
                if (!string.IsNullOrEmpty(input.Input))
                {
                    dicVariables[upperExtendedData] = input.Input;
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT)
            {
                if (dicVariables.ContainsKey(upperExtendedData))
                {
                    SuperMacroWriter textWriter = new SuperMacroWriter(connection);
                    textWriter.SendInput(dicVariables[upperExtendedData], settings, null, false);
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Output called for {upperExtendedData} without an Input beforehand");
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSETALL)
            {
                dicVariables.Clear();
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_UNSET)
            {
                if (string.IsNullOrEmpty(upperExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Unset called without variable name");
                    return;
                }
                if (dicVariables.ContainsKey(upperExtendedData))
                {
                    dicVariables.Remove(upperExtendedData);
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET || command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE)
            {
                if (string.IsNullOrEmpty(macro.ExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Set called without variable name");
                    return;
                }

                var splitData = macro.ExtendedData.Split(new char[] { ':' }, 2);
                if (splitData.Length != 2)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable Set called without incorrect extended data: {macro.ExtendedData}");
                    return;
                }
                string varInput = splitData[1];

                // Set From File but file doesn't exist
                if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE && !File.Exists(splitData[1]))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Variable SetFromFile called but file does not exist {splitData[1]}");
                    return;
                }
                else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_FILE) // File DOES exist
                {
                    varInput = File.ReadAllText(splitData[1]);
                }

                dicVariables[splitData[0].ToUpperInvariant()] = varInput;
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_FROM_CLIPBOARD)
            {
                var value = ReadFromClipboard();

                // Value exists (cancel button was NOT pressed)
                if (!string.IsNullOrEmpty(value))
                {
                    dicVariables[upperExtendedData] = value;
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_OUTPUT_TO_FILE)
            {
                if (string.IsNullOrEmpty(macro.ExtendedData))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile called without any params");
                    return;
                }

                var splitData = macro.ExtendedData.Split(new char[] { ':' }, 2);
                if (splitData.Length != 2)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile called without incorrect extended data: {macro.ExtendedData}");
                    return;
                }

                string variableName = splitData[0].ToUpperInvariant();
                string fileName     = splitData[1];

                // Check if variable exists
                if (!dicVariables.ContainsKey(variableName))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile called without non existing variable: {variableName}");
                    return;
                }

                // Try to save the data in the variable to the filename
                try
                {
                    File.WriteAllText(fileName, dicVariables[variableName]);
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"OutputToFile exception: {macro.ExtendedData} {ex}");
                }
                return;
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_RUN)
            {
                try
                {
                    upperExtendedData = upperExtendedData.ToLower();
                    upperExtendedData = upperExtendedData.Trim();
                    int pos = upperExtendedData.IndexOf(".exe", StringComparison.InvariantCultureIgnoreCase);
                    if (pos == -1)
                    {
                        return;
                    }
                    string exePath = upperExtendedData.Substring(0, pos + 4);
                    string args    = "";
                    if (!upperExtendedData.EndsWith(".exe"))
                    {
                        args = upperExtendedData.Substring(pos + 5, upperExtendedData.Length - (pos + 5));
                    }

                    if (File.Exists(exePath))
                    {
                        if (args != "")
                        {
                            Process.Start(exePath, args);
                        }
                        else
                        {
                            Process.Start(exePath.ToLower());
                        }
                    }
                    return;
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, string.Format("Run exception: {0} {1}", macro.ExtendedData, ex));
                    return;
                }
            }
            else if (command == ExtendedCommand.EXTENDED_MACRO_VARIABLE_SET_PROFILE)
            {
                try
                {
                    connection.SwitchProfileAsync(upperExtendedData).Wait();
                    return;
                }
                catch (Exception arg2)
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, string.Format("SetProfile exception: {0} {1}", macro.ExtendedData, arg2));
                    return;
                }
            }
            else
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"HandleVariableCommand - Invalid command {command}");
            }
        }