Esempio n. 1
0
        private void InputDetection_InputDetected1(CommandType inputType, Keys key, int x, int y, bool mouseWheelDirection, bool rightMouseButton)
        {
            if (m_lastCommandTime != DateTime.MinValue)
            {
                CommandWait cw = new CommandWait((int)(DateTime.Now - m_lastCommandTime).TotalMilliseconds, Macro.GetMacroByChild(m_node));
                cw.Duration = Math.Max(cw.Duration, 30);
                m_node.Nodes.Add(cw);
            }

            CommandInput ci = new CommandInput(inputType, key, x, y, mouseWheelDirection, rightMouseButton, Macro.GetMacroByChild(m_node));

            m_node.Nodes.Add(ci);

            m_lastCommandTime = DateTime.Now;
        }
Esempio n. 2
0
        public FormCommandInput(CommandInput commandInput, Macro macro)
        {
            InitializeComponent();

            CommandInput = commandInput;
            m_macro      = macro;

            cbKeyboardMode.SelectedIndex        = 0;
            cbMouseButton.SelectedIndex         = 0;
            cbMouseMode.SelectedIndex           = 0;
            cbMouseWheelDirection.SelectedIndex = 0;

            if (commandInput.InputType == CommandType.MouseDown || commandInput.InputType == CommandType.MouseUp)
            {
                rbSelectMousebutton.Checked = true;
                rbSelectMouseWheel.Checked  = false;
                rbSelectKeyboardKey.Checked = false;

                cbMouseButton.SelectedIndex = (commandInput.IsRightButton ? 0 : 1);
                cbMouseMode.SelectedIndex   = (commandInput.InputType == CommandType.MouseDown ? 0 : 1);
                nudMouseX.Value             = commandInput.X;
                nudMouseY.Value             = commandInput.Y;
            }
            else if (commandInput.InputType == CommandType.MouseWheel)
            {
                rbSelectMousebutton.Checked = false;
                rbSelectMouseWheel.Checked  = true;
                rbSelectKeyboardKey.Checked = false;

                cbMouseWheelDirection.SelectedIndex = (commandInput.IsMouseWheelUp ? 0 : 1);
            }
            else if (commandInput.InputType == CommandType.KeyDown || commandInput.InputType == CommandType.KeyUp)
            {
                rbSelectMousebutton.Checked = false;
                rbSelectMouseWheel.Checked  = false;
                rbSelectKeyboardKey.Checked = true;

                m_key = commandInput.Key;
                lbKeyboardKey.Text           = commandInput.Key.ToString();
                cbKeyboardMode.SelectedIndex = (commandInput.InputType == CommandType.KeyDown ? 0 : 1);
            }
        }
Esempio n. 3
0
        public override void ExecuteCommand()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int duration = CompensateDuration();

            Macros.AddLog("Play: Wait for " + Duration + "(" + duration + ")ms");

            //create little steps between two mouse events/positions
            bool waitWithSteps = false;

            if (Index + 1 < Parent.Nodes.Count && Index - 1 >= 0 && m_macro.SettingsMacro.MouseMoveInterpolationActive)
            {
                Command cia1 = (Command)Parent.Nodes[Index - 1];
                Command cia2 = (Command)Parent.Nodes[Index + 1];

                if (cia1.GetType() == typeof(CommandInput) && cia2.GetType() == typeof(CommandInput))
                {
                    CommandInput ci1 = (CommandInput)cia1;
                    CommandInput ci2 = (CommandInput)cia2;

                    if ((ci1.InputType == CommandType.MouseDown || ci1.InputType == CommandType.MouseUp) &&
                        (ci2.InputType == CommandType.MouseDown || ci2.InputType == CommandType.MouseUp))
                    {
                        int calcTime = 0;

                        PointF p1     = new PointF(ci1.X, ci1.Y);
                        PointF p2     = new PointF(ci2.X, ci2.Y);
                        PointF pDelta = new PointF(
                            (ci2.X - ci1.X) / ((float)duration / (float)m_macro.SettingsMacro.MouseMoveInterpolationInterval),
                            (ci2.Y - ci1.Y) / ((float)duration / (float)m_macro.SettingsMacro.MouseMoveInterpolationInterval));
                        PointF pCurrent = new PointF(ci1.X, ci1.Y);

                        for (int j = 0; j < duration; j += m_macro.SettingsMacro.MouseMoveInterpolationInterval)
                        {
                            pCurrent.X += pDelta.X;
                            pCurrent.Y += pDelta.Y;

                            if (m_macro.SettingsMacro.RelativeMouseMove)
                            {
                                int relX = (int)(pCurrent.X) - m_macro.LastMousePosition.X;
                                int relY = (int)(pCurrent.Y) - m_macro.LastMousePosition.Y;

                                Mouse.MoveRelative(relX, relY);

                                m_macro.LastMousePosition = new Point((int)pCurrent.X, (int)pCurrent.Y);
                            }
                            else
                            {
                                Mouse.Move((int)pCurrent.X, (int)pCurrent.Y);
                            }

                            if (j == 0)
                            {
                                calcTime += duration % m_macro.SettingsMacro.MouseMoveInterpolationInterval;
                            }
                            else
                            {
                                calcTime += m_macro.SettingsMacro.MouseMoveInterpolationInterval;
                            }

                            Thread.Sleep(Math.Max(0, calcTime - (int)sw.ElapsedMilliseconds));
                        }
                        waitWithSteps = true;
                    }
                }
            }

            if (!waitWithSteps)
            {
                Thread.Sleep(duration - (int)sw.ElapsedMilliseconds);
            }
        }
Esempio n. 4
0
        private void ReadJSONCommand(dynamic json, TreeNode currentNode, int index)
        {
            dynamic d;

            try
            {
                d = json.commands;
            }
            catch (RuntimeBinderException)
            {
                d = json;
            }
            foreach (dynamic command in d)
            {
                switch ((string)command.type)
                {
                case "KeyDown":
                    CommandInput ci1 = new CommandInput(CommandType.KeyDown, command.keyCode.ToObject <Keys>(), 0, 0, false, false, this);
                    currentNode.Nodes.Add(ci1);
                    break;

                case "KeyUp":
                    CommandInput ci2 = new CommandInput(CommandType.KeyUp, command.keyCode.ToObject <Keys>(), 0, 0, false, false, this);
                    currentNode.Nodes.Add(ci2);
                    break;

                case "MouseDown":
                    CommandInput ci3 = new CommandInput(CommandType.MouseDown, Keys.None, command.x.ToObject <int>(), command.y.ToObject <int>(), false, (command.button.ToObject <string>() == "right" ? true : false), this);
                    currentNode.Nodes.Add(ci3);
                    break;

                case "MouseUp":
                    CommandInput ci4 = new CommandInput(CommandType.MouseUp, Keys.None, command.x.ToObject <int>(), command.y.ToObject <int>(), false, (command.button.ToObject <string>() == "right" ? true : false), this);
                    currentNode.Nodes.Add(ci4);
                    break;

                case "MouseMove":
                    CommandInput ci41 = new CommandInput(CommandType.MouseMove, Keys.None, command.x.ToObject <int>(), command.y.ToObject <int>(), false, false, this);
                    currentNode.Nodes.Add(ci41);
                    break;

                case "MouseWheel":
                    CommandInput ci5 = new CommandInput(CommandType.MouseWheel, Keys.None, command.x.ToObject <int>(), command.y.ToObject <int>(), (command.wheelDirection.ToObject <string>() == "up" ? true : false), false, this);
                    currentNode.Nodes.Add(ci5);
                    break;

                case "wait":
                    CommandWait ci6 = new CommandWait(command.duration.ToObject <int>(), this);
                    currentNode.Nodes.Add(ci6);
                    break;

                case "condition":
                    CommandCondition ci8 = new CommandCondition();
                    currentNode.Nodes.Add(ci8);
                    foreach (dynamic j in command.conditions)
                    {
                        ci8.Nodes[0].Nodes.Add(new ConditionNode(ReadJSONCondition(j)));
                    }
                    ReadJSONCommand(command.thenCommands, ci8.Nodes[1], 0);
                    ReadJSONCommand(command.elseCommands, ci8.Nodes[2], 0);
                    break;

                case "replayMacro":
                    CommandReplayMakro ci9 = new CommandReplayMakro((string)command.name, this);
                    currentNode.Nodes.Add(ci9);
                    break;

                case "setVariable":
                    Variable v = new Variable((string)command.variable, "");
                    this.Variables.Add(v);
                    CommandSetVariable ci10 = new CommandSetVariable(v, ReadJSONOutput(command.output), this);
                    currentNode.Nodes.Add(ci10);
                    break;

                case "writeFile":
                    string fileName = (string)command.fileName;
                    fileName = fileName.Replace("\\\\", "\\");
                    CommandWriteFile ci11 = new CommandWriteFile(fileName, (string)command.text, (bool)command.appendFile, this);
                    currentNode.Nodes.Add(ci11);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Esempio n. 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (rbSelectMousebutton.Checked)
            {
                gbMouseButton.Enabled = true;
                gbMouseWheel.Enabled  = false;
                gbKeyboardKey.Enabled = false;

                if (cbMouseMode.SelectedIndex == 0)
                {
                    CommandInput = new CommandInput(
                        CommandType.MouseDown,
                        Keys.None,
                        (int)nudMouseX.Value,
                        (int)nudMouseY.Value,
                        false,
                        (cbMouseButton.SelectedIndex == 0 ? true : false),
                        m_macro
                        );
                }
                else
                {
                    CommandInput = new CommandInput(
                        CommandType.MouseUp,
                        Keys.None,
                        (int)nudMouseX.Value,
                        (int)nudMouseY.Value,
                        false,
                        (cbMouseButton.SelectedIndex == 0 ? true : false),
                        m_macro
                        );
                }
            }
            else if (rbSelectMouseWheel.Checked)
            {
                gbMouseButton.Enabled = false;
                gbMouseWheel.Enabled  = true;
                gbKeyboardKey.Enabled = false;

                CommandInput = new CommandInput(
                    CommandType.MouseWheel,
                    Keys.None,
                    (int)nudMouseX.Value,
                    (int)nudMouseY.Value,
                    (cbMouseWheelDirection.SelectedIndex == 0 ? true : false),
                    false,
                    m_macro
                    );
            }
            else if (rbSelectKeyboardKey.Checked)
            {
                gbMouseButton.Enabled = false;
                gbMouseWheel.Enabled  = false;
                gbKeyboardKey.Enabled = true;

                if (cbKeyboardMode.SelectedIndex == 0)
                {
                    CommandInput = new CommandInput(
                        CommandType.KeyDown,
                        m_key,
                        0,
                        0,
                        false,
                        false,
                        m_macro
                        );
                }
                else
                {
                    CommandInput = new CommandInput(
                        CommandType.KeyUp,
                        m_key,
                        0,
                        0,
                        false,
                        false,
                        m_macro
                        );
                }
            }

            if (rbSelectKeyboardKey.Checked && m_key == Keys.None)
            {
                MessageBox.Show("Es muss eine Taste ausgewählt sein", "Keine Taste gewählt", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DialogResult = DialogResult.OK;
            }
        }