Exemplo n.º 1
0
        private void Tick(object sender, EventArgs e)
        {
            User32.GetCursorPos(out var p);
            this.Text = $"({p.X}, {p.Y})";

            using (var screenshot = this.tracker.GetScreenshot())
            {
                var grid   = GridUtil.GetGridFromScreeshot(screenshot, this.CurrentGameMode);
                var blocks = Analizer.AnalizeGridImage(this.templates, grid);
                this.lastGrid = blocks;

                (var output, var overlay) = GenerateOutput(blocks);

                this.pcGrid.Image   = grid;
                this.pcOutput.Image = output;

                if (this.overlayForm != null)
                {
                    this.overlayForm.SetImage(overlay);
                    var offset = GridLocator.LocateGrid(this.CurrentGameMode);
                    var rect   = this.tracker.GetWindowRect();
                    this.overlayForm.Location = new Point(rect.Left + offset.X, rect.Top + offset.Y);
                }
            }
        }
Exemplo n.º 2
0
        private void pcOutput_Click(object sender, EventArgs e)
        {
            var mouseEvent = (MouseEventArgs)e;

            var coluna = (int)Math.Floor((decimal)mouseEvent.X / C.BlockWidth);
            var linha  = (int)Math.Floor((decimal)mouseEvent.Y / C.BlockHeight);
            var window = this.tracker.GetWindowRect();
            var offset = GridLocator.LocateGrid(this.CurrentGameMode);

            var x = (window.X + offset.X + (coluna * C.BlockWidth)) + C.BlockWidth / 2;
            var y = (window.Y + offset.Y + (linha * C.BlockHeight)) + C.BlockHeight / 2;

            Debug.WriteLine($"Click at ({x}, {y})");

            var old = Cursor.Position;

            Cursor.Position = new Point(x, y);

            this.tracker.SetActive();
            User32.MouserEvent((int)User32.MouseEventFlags.LeftDown, (uint)x, (uint)y, 0, 0);
            User32.MouserEvent((int)User32.MouseEventFlags.LeftUp, (uint)x, (uint)y, 0, 0);

            Cursor.Position = old;
            //var p = Process.GetCurrentProcess();
            //ApplicationTracker.SetWindowActive(p.Handle, p.MainWindowHandle);
        }