//---------------------------------------------------
        //          BarRaider's Hall Of Fame
        // CyberlightGames - 1 Gifted Subs
        //---------------------------------------------------
        //          Honorary Mention
        // Marbles On Stream winner: xntss
        //---------------------------------------------------
        public static void HandleFunctionRequest(string functionData, Dictionary <string, string> dicVariables)
        {
            if (dicVariables == null)
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Dictionary is null");
                return;
            }

            string[] parameters = functionData.Split(':');
            if (parameters.Length < 3)
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Invalid number of params {functionData}");
                return;
            }

            // Handle the incoming parameters
            string functionName   = parameters[0].ToUpperInvariant();
            string outputVariable = parameters[1].ToUpperInvariant();

            for (int currentParam = 2; currentParam < parameters.Length; currentParam++)
            {
                parameters[currentParam] = ExtendedMacroHandler.TryExtractVariable(parameters[currentParam]);
            }

            // Try and figure out the right function to call
            FunctionPointer requestedFunction = RetreiveRequestedFunction(functionName);

            if (requestedFunction == null)
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Invalid function name {functionName}");
                return;
            }

            string result = requestedFunction(parameters.Skip(2).ToArray());

            if (result == null)
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Invalid result from {functionName}");
                return;
            }

            dicVariables[outputVariable] = result;
        }
Ejemplo n.º 2
0
        private static VirtualKeyCodeContainer MacroTextToKeyCode(string macroText)
        {
            try
            {
                if (ExtendedMacroHandler.IsExtendedMacro(macroText, out string macroCommand, out string extendedData))
                {
                    return(new VirtualKeyCodeContainer(VirtualKeyCode.ZOOM, macroCommand, extendedData));
                }

                string         text    = ConvertSimilarMacroCommands(macroText.ToUpperInvariant());
                VirtualKeyCode keyCode = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), text, true);
                return(new VirtualKeyCodeContainer(keyCode));
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"MacroTextToInt Exception: {ex}");
                return(null);
            }
        }
Ejemplo n.º 3
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);
                        }
                    }
                }
            }
        }