Exemplo n.º 1
0
            public override void Step(float x, Robot r)
            {
                Point p  = CursorMonitor.Position();
                float fx = -((x - 1) * (x - 1)) + 1;
                float dx = this.x - p.X;
                float dy = this.y - p.Y;

                dx *= fx; dy *= fx;
                dx += 0.5f; dy += 0.5f;
                r.DoAction(MouseAction.WM_MOUSEMOVE, (int)(p.X + dx), (int)(p.Y + dy));
            }
Exemplo n.º 2
0
        private void selectDelegate(OnMouseLocationSelected callback, Action <int, int> update)
        {
            show(MyColors.BLUE);

            Action loop = null;

            object syncLock    = new object();
            bool   followMouse = true;

            Hook.OnMouseDelegate mouseDown = null;
            mouseDown = (ma, x, y) =>
            {
                if (ma != MouseAction.WM_LBUTTONDOWN)
                {
                    return;
                }

                lock (syncLock)
                {
                    followMouse = false;
                }

                hide();

                System.Drawing.Point p = CursorMonitor.Position();
                Hook.I().RemoveMouseHook(mouseDown).ContinueWith((t) =>
                {
                    loop = () => { };
                    callback(p.X, p.Y);
                });
            };
            Hook.I().AddMouseHook(mouseDown);

            Hook.OnKeyDelegate keyU = (k) => { };
            Hook.OnKeyDelegate keyD = null;
            keyD = (k) =>
            {
                if (k != Key.Escape)
                {
                    return;
                }

                lock (syncLock)
                {
                    followMouse = false;
                }

                Dispatcher.Invoke(() =>
                {
                    WindowState = WindowState.Minimized;
                    Visibility  = Visibility.Hidden;
                });

                Hook.I().RemoveKeyHook(keyD, keyU).ContinueWith((t) =>
                {
                    return(Hook.I().RemoveMouseHook(mouseDown));
                }).ContinueWith((t) =>
                {
                    callback(0, 0, true);
                });
            };
            Hook.I().AddKeyHook(keyD, keyU);

            TextBlock coords = new TextBlock();

            coords.Foreground = new SolidColorBrush(Colors.Black);
            coords.Background = new SolidColorBrush(Colors.White);
            coords.Padding    = new Thickness(4);

            loop = () =>
            {
                Topmost = true;

                canvas.Children.Clear();
                System.Drawing.Point p = CursorMonitor.Position();
                p.X = p.X == 0 ? 0 : p.X - 2;
                p.Y = p.Y == 0 ? 0 : p.Y - 2;
                update(p.X, p.Y);

                Line h = new Line();
                h.Stroke          = new SolidColorBrush(BLUE);
                h.StrokeThickness = 2;
                h.X1 = 0; h.X2 = W;
                h.Y1 = p.Y; h.Y2 = p.Y;

                Line v = new Line();
                v.Stroke          = new SolidColorBrush(BLUE);
                v.StrokeThickness = 2;
                v.X1 = p.X; v.X2 = p.X;
                v.Y1 = 0; v.Y2 = H;

                coords.Text = p.X + ", " + p.Y;
                double fac    = 15;
                double coordX = W - p.X < coords.ActualWidth + fac ? W - (coords.ActualWidth + fac) : p.X + 4;
                double coordY = p.Y < coords.ActualHeight + fac ? coords.ActualHeight + fac : p.Y;

                Canvas.SetLeft(coords, coordX);
                Canvas.SetBottom(coords, H - coordY);

                canvas.Children.Add(h);
                canvas.Children.Add(v);
                canvas.Children.Add(coords);

                //return;
                lock (syncLock)
                {
                    if (!followMouse)
                    {
                        return;
                    }
                }

                Task.Delay(16).ContinueWith((t) =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        loop();
                    });
                });
            };
            Dispatcher.Invoke(loop);
        }