Esempio n. 1
0
 public static void ConvertEvent(List <MacroEvent> events)
 {
     foreach (var item in events)
     {
         if (item.EventArgs is MouseEventArgs)
         {
             MouseEventArgs   arg    = (MouseEventArgs)item.EventArgs;
             MyMouseEventArgs myArgs = new MyMouseEventArgs(arg.Button, arg.Clicks, arg.X, arg.Y, arg.Delta);
             item.EventArgs = myArgs;
         }
         else if (item.EventArgs is KeyEventArgs)
         {
             KeyEventArgs   arg    = (KeyEventArgs)item.EventArgs;
             MyKeyEventArgs myArgs = new MyKeyEventArgs(arg.KeyCode);
             item.EventArgs = myArgs;
         }
     }
 }
Esempio n. 2
0
        public static void WorkThreadFunction(List <MacroEvent> events, int times)
        {
            try
            {
                ConvertEvent(events);
                isCancel = false;
                for (int i = 0; i < times; i++)
                {
                    foreach (MacroEvent macroEvent in events)
                    {
                        if (isCancel)
                        {
                            break;
                        }
                        Thread.Sleep(macroEvent.TimeSinceLastEvent);

                        switch (macroEvent.MacroEventType)
                        {
                        case MacroEventType.MouseMove:
                        {
                            MyMouseEventArgs mouseArgs = (MyMouseEventArgs)macroEvent.EventArgs;

                            MouseSimulator.X = mouseArgs.X;
                            MouseSimulator.Y = mouseArgs.Y;
                        }
                        break;

                        case MacroEventType.MouseDown:
                        {
                            MyMouseEventArgs mouseArgs = (MyMouseEventArgs)macroEvent.EventArgs;

                            MouseSimulator.MouseDown(mouseArgs.Button);
                        }
                        break;

                        case MacroEventType.MouseUp:
                        {
                            MyMouseEventArgs mouseArgs = (MyMouseEventArgs)macroEvent.EventArgs;

                            MouseSimulator.MouseUp(mouseArgs.Button);
                        }
                        break;

                        case MacroEventType.KeyDown:
                        {
                            MyKeyEventArgs keyArgs = (MyKeyEventArgs)macroEvent.EventArgs;

                            KeyboardSimulator.KeyDown(keyArgs.KeyCode);
                        }
                        break;

                        case MacroEventType.KeyUp:
                        {
                            MyKeyEventArgs keyArgs = (MyKeyEventArgs)macroEvent.EventArgs;

                            KeyboardSimulator.KeyUp(keyArgs.KeyCode);
                        }
                        break;

                        default:
                            break;
                        }
                    }
                    if (times > 1)
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }