Beispiel #1
0
        private void KeyboardHook_KeyDown(KeyboardHook.VKeys key)
        {
            ///Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] KeyDown Event {" + key.ToString() + "}");
            p.x = Cursor.Position.X;
            p.y = Cursor.Position.Y;
            int step = 15;

            switch (key)
            {
            case KeyboardHook.VKeys.UP:
                p.y -= step;
                break;

            case KeyboardHook.VKeys.DOWN:
                p.y += step;
                break;

            case KeyboardHook.VKeys.LEFT:
                p.x -= step;
                break;

            case KeyboardHook.VKeys.RIGHT:
                p.x += step;
                break;

            case KeyboardHook.VKeys.SPACE:
                //ClickOnPointTool.ClickOnPoint(this.Handle,new Point(p.x , p.y));
                ClickOnPointTool.ClickOn(this.Handle, new Point(p.x, p.y));
                break;

            default:
                break;
            }

            Console.WriteLine($"{p.x} , {p.y} , {key}");
            Cursor.Position = new Point(p.x, p.y);
            //Cursor.Clip = new Rectangle(this.Location, this.Size); //block cursor exit from form dimensions
        }
Beispiel #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (!isRunning)
            {
                if (!BotHelper.setMemuIntPtr())
                {
                    MetroFramework.MetroMessageBox.Show(this, "MEmu is not running!");
                    return;
                }

                if (chkUseSidebar.Checked)
                {
                    ClickOnPointTool.ResizeWindow(BotHelper.memu, 1328, 758);
                }
                else
                {
                    ClickOnPointTool.ResizeWindow(BotHelper.memu, 1288, 758);
                }

                btnStart.Text = "Stop";
                isRunning     = true;

                // Start the Bot thread
                Thread.Sleep(100);
                thread = new Thread(doLoop);
                thread.IsBackground = true;
                thread.Start();
            }
            else
            {
                if (thread.IsAlive)
                {
                    thread.Suspend(); // TODO: Proper Multithreading
                }
                btnStart.Text = "Start";
                isRunning     = false;
            }
        }
Beispiel #3
0
        void OneWindow()
        {
            IntPtr win = FindWindow("Valve001", "Counter-Strike: Global Offensive");

            if (win == IntPtr.Zero)
            {
                toolStripStatusLabel2.Text = "CS:GO is not running!"; return;
            }
            int r = 0; int mm = 0;
            int iter   = Int32.Parse(textBox1.Text);
            var pixel1 = Win32.GetPixelColor(win, p1x, p1y);
            var pixel2 = Win32.GetPixelColor(win, p2x, p2y);
            var pixel7 = Win32.GetPixelColor(win, p7x, p7y);

            if (pixel1.R != 255 && pixel1.G != 255 & pixel1.B != 255 && pixel2.R != 0 && pixel2.G != 0 & pixel2.B != 0)
            {
                toolStripStatusLabel2.Text = "You're not in the main menu!";  goto ll2;
            }
            else
            {
                toolStripStatusLabel1.Text = "Working";
                for (int i = 0; i < iter; i++)
                {
                    mm++;
                    toolStripStatusLabel2.Text = "Iteration: " + (i) + "/" + iter + " (reconnects: " + r + ")";
                    int m = 0;
                    while (m < 500)
                    {
                        m++;
                        pixel1 = Win32.GetPixelColor(win, p1x, p1y);
                        pixel2 = Win32.GetPixelColor(win, p2x, p2y);
                        pixel7 = Win32.GetPixelColor(win, p7x, p7y);
                        if (pixel1.R == 255 && pixel1.G == 255 && pixel1.B == 255 && pixel2.R == 0 && pixel2.G == 0 && pixel2.B == 0 && pixel7.R == 0)
                        {
                            goto l2;
                        }
                        if (pixel1.R == 255 && pixel1.G == 255 && pixel1.B == 255 && pixel2.R == 0 && pixel2.G == 0 && pixel2.B == 0 && pixel7.R != 0)
                        {
                            goto l1;
                        }
                        System.Threading.Thread.Sleep(5000);
                        Application.DoEvents();
                    }
                    l1 : Cursor.Position = new Point(p7x, p7y);                      // Reconnect Button
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position); r++; goto ll1;
                    l2 : Cursor.Position = new Point(p1x, p1y);                      // Play Button
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position);
                    System.Threading.Thread.Sleep(1000);
                    Cursor.Position = new Point(p4x, p4y);                            // Wingman mode select
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position);
                    System.Threading.Thread.Sleep(1000);
                    var pixel5 = Win32.GetPixelColor(win, p5x, p5y);
                    Cursor.Position = new Point(p5x, p5y);                          // Search the match Button
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position);
                    System.Threading.Thread.Sleep(300);
                    var pixel6 = Win32.GetPixelColor(win, p5x, p5y);
                    if (pixel6.R != pixel5.R)
                    {
                        goto l3;
                    }
                    System.Threading.Thread.Sleep(500);
                    Cursor.Position = new Point(p5x, p5y);                          // Search the match Button one more time
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position);
                    l3 : System.Threading.Thread.Sleep(1000);
                    var pixel3 = Win32.GetPixelColor(win, p3x, p3y);
                    int n      = 0;
                    while (n < 150)
                    {
                        System.Threading.Thread.Sleep(5000);
                        n++;
                        var pixel4 = Win32.GetPixelColor(win, p3x, p3y);
                        if (pixel4.R != pixel3.R)
                        {
                            goto l4;
                        }
                        Application.DoEvents();
                    }
                    l4 : var pixel8 = Win32.GetPixelColor(win, p3x, p3y);
                    System.Threading.Thread.Sleep(1000);
                    Cursor.Position = new Point(p6x, p6y);
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position);
                    System.Threading.Thread.Sleep(1000);
                    Cursor.Position = new Point(p6x, p6y);
                    ClickOnPointTool.ClickOnPoint(win, Cursor.Position);
                    int p = 0;
                    while (p < 30)
                    {
                        System.Threading.Thread.Sleep(3000);
                        p++;
                        var pixel9 = Win32.GetPixelColor(win, p3x, p3y);
                        if (pixel9.R == pixel8.R && pixel9.G == pixel8.G)
                        {
                            goto l4;
                        }
                        Application.DoEvents();
                    }
                    Application.DoEvents();
                    ll1 : System.Threading.Thread.Sleep(1000);
                }
            }
            pixel1 = Win32.GetPixelColor(win, p1x, p1y);
            pixel2 = Win32.GetPixelColor(win, p2x, p2y);
            pixel7 = Win32.GetPixelColor(win, p7x, p7y);
            if (pixel1.R == 255 && pixel1.G == 255 && pixel1.B == 255 && pixel2.R == 0 && pixel2.G == 0 && pixel2.B == 0 && pixel7.R == 0)
            {
                toolStripStatusLabel1.Text = "Ready"; toolStripStatusLabel2.Text = "Done: " + mm + " cycles" + " (reconnects: " + r + "of this reconnects"; return;
            }
            ll2 : System.Threading.Thread.Sleep(1000);
        }
Beispiel #4
0
        // Start the fight by clicking anywhere and wait for it to end (by searching for the "OK" button)
        public static bool startDuell(int attempt = 1)
        {
            ClickOnPointTool.ClickOnPoint(BotHelper.memu, new Point(rnd.Next(670 - 100, 670 + 100), rnd.Next(400 - 100, 400 + 100))); //Click anywhere to start the battle
            BotHelper.randomDelay(500, 50);

            // wait for the duell to end and click on ok
            BotHelper.Log("Waiting for the duell to end.");
            int   checks = 0;
            Point locOK  = new Point();

            do
            {
                BotHelper.Log(" " + checks, false);
                Thread.Sleep(500);
                checks++;

                // Apparently, there are multiple "OK"-Buttons that all look the same at a first glance,
                // but there's a difference in them that the tool is able to detect.
                // We have to check multiple images because of this, but we got an easy detection whether
                // we won or not. :)

                locOK = ImageRecognition.getPictureLocation(Properties.Resources.button_ok, BotHelper.memu);
                //locOKDefeat = ImageRecognition.getPictureLocation(Properties.Resources.button_ok_defeat, BotHelper.memu);
            } while ((locOK == pNull /* && locOKDefeat == pNull */) && checks <= 55);

            if (checks >= 55)
            {
                BotHelper.Log("We timed out. :(");
            }

            BotHelper.randomDelay(500, 50);
            if (locOK.X == 0 && locOK.Y == 0) //something went wrong (note: the code should never enter this)
            {
                BotHelper.Log("Something weird happened.");
                if (attempt < 3)
                {
                    return(startDuell(attempt + 1));
                }
                else
                {
                    return(false); // TODO: Restart CATS?
                }
            }
            else //we won!
            {
                BotHelper.Log("Battle finished.");

                int winloss = checkWin();
                if (winloss == 1)
                {
                    BotHelper.Log("We won!");
                    wins++;
                    winsInARow++;
                    if ((winsInARow % 5) == 0)
                    {
                        crowns++;
                    }
                }
                else if (winloss == 2)
                {
                    BotHelper.Log("We lost. :(");
                    losses++;
                    winsInARow = 0;
                }
                else
                {
                    BotHelper.Log("Error checking win/loss, not counting stats");
                }

                BotHelper.updateStats(wins, losses, crowns);

                Point rndP = ImageRecognition.getRandomLoc(locOK, Properties.Resources.button_ok);
                BotHelper.Log("Clicked on: X = " + rndP.X + "; Y = " + rndP.Y, true, true);
                ClickOnPointTool.ClickOnPoint(BotHelper.memu, rndP);
            }

            //BotHelper.UpdateStats(wins, losses, crowns);
            BotHelper.Log("Returning to main screen");

            return(true);
        }
Beispiel #5
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            var wHandle = ClickOnPointTool.FindWindow(txtClass.Text, txtName.Text);

            if (wHandle.ToInt64() > 0)
            {
                var          no   = lsvScripts.Items.Count + 1;
                ListViewItem item = new ListViewItem((no).ToString());
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, txtDelay.Text));
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, $"X1:{txtXPos.Text}, Y1:{txtYPos.Text}, Color1:{txtColor1.Text} | X2:{txtX2.Text}, Y2:{txtY2.Text}, Color2:{txtColor2.Text} | XMoved:{txtXMoved.Text}, YMoved:{txtYMoved.Text}, ColorMoved:{txtColorMoved.Text}"));
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, txtDescription.Text));
                lsvScripts.Items.Add(item);

                Configs.Add(new Configuration.Config
                {
                    No = no,

                    XPos      = string.IsNullOrWhiteSpace(txtXPos.Text) ? 0 : int.Parse(txtXPos.Text),
                    YPos      = string.IsNullOrWhiteSpace(txtYPos.Text) ? 0 : int.Parse(txtYPos.Text),
                    ColorName = txtColor1.Text,

                    X2Pos      = string.IsNullOrWhiteSpace(txtX2.Text) ? 0 : int.Parse(txtX2.Text),
                    Y2Pos      = string.IsNullOrWhiteSpace(txtY2.Text) ? 0 : int.Parse(txtY2.Text),
                    Color2Name = txtColor2.Text,

                    XPosIgnored      = string.IsNullOrWhiteSpace(txtXIgnored1.Text) ? 0 : int.Parse(txtXIgnored1.Text),
                    YPosIgnored      = string.IsNullOrWhiteSpace(txtYIgnored1.Text) ? 0 : int.Parse(txtYIgnored1.Text),
                    ColorIgnoredName = txtColorIgnored1.Text,

                    XPosMoved      = string.IsNullOrWhiteSpace(txtXMoved.Text) ? 0 : int.Parse(txtXMoved.Text),
                    YPosMoved      = string.IsNullOrWhiteSpace(txtYMoved.Text) ? 0 : int.Parse(txtYMoved.Text),
                    ColorMovedName = txtColorMoved.Text,

                    IsSequential = rdoSequencial.Checked,
                    Description  = txtDescription.Text,
                    Delay        = string.IsNullOrWhiteSpace(txtDelay.Text) ? 200 : int.Parse(txtDelay.Text),
                    IsDrag       = chkDrag.Checked,

                    IsStartIcon = chkIsStartIcon.Checked,
                    RunOnce     = chkRunOnce.Checked,
                });

                // Reset click points
                txtXPos.Clear();
                txtYPos.Clear();
                txtColor1.Clear();
                txtX2.Clear();
                txtY2.Clear();
                txtColor2.Clear();
                txtXIgnored1.Clear();
                txtYIgnored1.Clear();
                txtColorIgnored1.Clear();

                chkDrag.Checked             = false;
                btnGetPositionMoved.Enabled = false;
                txtXMoved.Clear();
                txtYMoved.Clear();
                txtColorMoved.Clear();
                txtDescription.Clear();

                chkIsStartIcon.Checked = false;
                chkRunOnce.Checked     = false;

                btnUpdateScript.Enabled = false;
            }
            else
            {
                MessageBox.Show("Application not found. Please re-take the control");
            }
        }
Beispiel #6
0
        private async Task RunAsync(Configuration.Config config)
        {
            //txtProgress.AppendText($"- Script No : {config.No}. Description: {config.Description}. {Environment.NewLine}");

            await Task.Delay(config.Delay);

            lock (padlock)
            {
                if (isRun == false)
                {
                    return;
                }
            }

            // Make Calculator the foreground application and send it
            // a set of calculations.

            ClickOnPointTool.SetForegroundWindow(config.WindowHandle);
            //ClickOnPointTool.ShowActiveWindow(config.WindowHandle);

            //if (LoadingConfigs != null && LoadingConfigs.Count > 0)
            //{
            //    var loadingItem = LoadingConfigs[0];
            //    var loadingColor = await MouseOperation.GetColorAt(new Point(loadingItem.XPos, loadingItem.YPos));
            //    while (loadingColor.Name == loadingItem.ColorName)
            //    {
            //        txtProgress.AppendText($"- Script No : {config.No}. Loading.... {Environment.NewLine}");

            //        loadingColor = await MouseOperation.GetColorAt(new Point(loadingItem.XPos, loadingItem.YPos));

            //    }
            //}

            if (config.IsSequential)
            {
                if (config.IsDrag)
                {
                    await ClickOnPointTool.ClickAndDragAsync(config.WindowHandle, new Point(config.XPos, config.YPos), config.ColorName, new Point(config.XPosMoved, config.YPosMoved), new Point(config.XPosIgnored, config.XPosIgnored), config.ColorMovedName);
                }
                else
                {
                    await MouseOperation.SendMessageAsync(config.WindowHandle,
                                                          (int)MouseOperation.MouseEventFlags.LeftDown, 1, config, LoadingConfigs);

                    await MouseOperation.SendMessageAsync(config.WindowHandle,
                                                          (int)MouseOperation.MouseEventFlags.LeftUp, 0, config, LoadingConfigs);
                }
            }
            else // Speed mode
            {
                if (config.IsDrag)
                {
                    await ClickOnPointTool.ClickAndDragAsync(config.WindowHandle, new Point(config.XPos, config.YPos), config.ColorName, new Point(config.XPosMoved, config.YPosMoved), new Point(config.XPosIgnored, config.XPosIgnored), config.ColorMovedName);
                }
                else
                {
                    var isOk = await MouseOperation.ClickSpeedModeAsync(config.WindowHandle, config);

                    if (isOk)
                    {
                        // Do something else
                        if (config.RunOnce)
                        {
                            config.IsDisabledTemp = true;
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public void Click(AutoAction action)
        {
            List <ClickOnPointTool.INPUT> inputs = new List <ClickOnPointTool.INPUT>();
            var chosenPoint = new Win32.POINT();

            // Move the mouse if required.
            if (action.locationType == LocationType.Fixed)
            {
                chosenPoint.x = action.x;
                chosenPoint.y = action.y;
            }
            else if (action.locationType == LocationType.Random)
            {
                chosenPoint.x = rnd.Next(65536);
                chosenPoint.y = rnd.Next(65536);
            }
            else if (action.locationType == LocationType.RandomRange)
            {
                chosenPoint.x = rnd.Next(action.x, action.x + action.width);
                chosenPoint.y = rnd.Next(action.y, action.y + action.height);
            }
            //Click Type
            for (int i = 0; i < (action.doubleClick ? 2 : 1); i++)
            {
                // Add a delay if it's a double click
                if (i == 1)
                {
                    Thread.Sleep(50);
                }

                if (action.buttonType == ButtonType.Left)
                {
                    ClickOnPointTool.INPUT inputDown = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.LeftDown
                            }
                        }
                    };
                    inputs.Add(inputDown);
                    ClickOnPointTool.INPUT inputUp = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.LeftUp
                            }
                        }
                    };
                    inputs.Add(inputUp);
                }

                if (action.buttonType == ButtonType.Middle)
                {
                    ClickOnPointTool.INPUT inputDown = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.MiddleDown
                            }
                        }
                    };
                    inputs.Add(inputDown);
                    ClickOnPointTool.INPUT inputUp = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.MiddleUp
                            }
                        }
                    };
                    inputs.Add(inputUp);
                }

                if (action.buttonType == ButtonType.Right)
                {
                    ClickOnPointTool.INPUT inputDown = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.RightUp
                            }
                        }
                    };
                    inputs.Add(inputDown);
                    ClickOnPointTool.INPUT inputUp = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.RightDown
                            }
                        }
                    };
                    inputs.Add(inputUp);
                }
            }

            if (inputs.Count > 0)
            {
                AutoCursor.MoveMouse(chosenPoint.x, chosenPoint.y, 0, 0);
            }

            Point lpPoint = new Point()
            {
                X = chosenPoint.x, Y = chosenPoint.y
            };

            //ClickOnPointTool.ClientToScreen(handle, ref lpPoint);

            //Another attempt, only supports left
            ClickOnPointTool.ClickOnPoint(handle, new System.Drawing.Point()
            {
                X = chosenPoint.x, Y = chosenPoint.y
            }, inputs.ToArray());
        }
 public static void ClickPosition(IntPtr hWnd, System.Windows.Point point)
 {
     ClickOnPointTool.ClickOnPoint(hWnd, point);
 }