Пример #1
0
        public FunctionDefinitions(Script script, ScreenCapturerBase screen_capturer = null)
        {
            // the script object contains additional parameters for the script
            // that are needed for script execution
            this.script = script;

            this.screen_capturer = screen_capturer ?? new ScreenCapturer();

            this.screen_color_detector = new ScreenColorDetector(this.screen_capturer);
        }
Пример #2
0
        public MouseActionPerformer(int PollingRate = PollingRateDefault,
                                    ICursorLocationSetter cursor_loc_setter   = null,
                                    ScreenColorDetector screen_color_detector = null)
        {
            this.PollingRate = PollingRate; // this also sets PollingPeriod
            this.Polled      = true;

            this.CursorLocationSetter = cursor_loc_setter ?? new MouseEventCursorLocationSetter();
            this.ScreenColorDetector  = screen_color_detector ?? new ScreenColorDetector();

            LeftButton   = new Button(Button.LeftDownCode, Button.LeftUpCode, this);
            RightButton  = new Button(Button.RightDownCode, Button.RightUpCode, this);
            MiddleButton = new Button(Button.MiddleDownCode, Button.MiddleUpCode, this);
        }
Пример #3
0
        /// <summary>
        /// Moves mouse cursor to a certain color
        /// </summary>
        /// <param name="screen_area">Rectangle representing coordinates of the screen area</param>
        /// <param name="move_color">Color to move to</param>
        /// <param name="timeout_ms">How long to wait before giving up, in milliseconds. 0 for unlimited time.</param>
        /// <param name="speed">Cursor move speed</param>
        /// <param name="comparer">A color comparer</param>
        /// <returns>True if success, false if timed out</returns>
        public bool MoveToColor(Rectangle screen_area, ColorChecker checker, int timeout_ms = 0, double speed = SpeedDefault)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Point p = new Point(0, 0);

            while ((p = ScreenColorDetector.LocationOfColorWithinScreenArea(
                        screen_area, checker)).X == -1)
            {
                if (timeout_ms != 0 && stopwatch.ElapsedMilliseconds >= timeout_ms)
                {
                    return(false);
                }
                Thread.Sleep(10);
            }
            MoveTo(p.X, p.Y, speed);
            return(true);
        }