Example #1
0
 public int BindWindow(int hwnd, int mode)
 {
     dm.SetWindowState(hwnd, 1);
     if (mode == 0)
     {
         return(dm.BindWindow(hwnd, "gdi", "normal", "normal", 0));
     }
     else
     {
         return(dm.BindWindow(hwnd, "gdi", "dx", "dx", 0));
     }
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string HeroName  = comboBox1.Text.ToString();
            var    LoLClient = DM.FindWindow("", "League of Legends");

            DM.BindWindow(LoLClient, "gdi", "windows3", "normal", 1);
            DM.MoveTo(860, 97);
            DM.LeftClick();
            DM.Capture(0, 0, 2000, 2000, "1.bmp");
            int isExsit = -1;
            //Enter hero name X Y;
            int    x = 784, y = 100;
            object x1, y2;

            while (true)
            {
                isExsit = DM.FindPic(0, 0, 2000, 2000, "Icon.bmp", "000000", 0.9, 0, out x1, out y2);
                if (isExsit >= 0)
                {
                    DM.MoveTo(860, 97);
                    Thread.Sleep(300);
                    DM.LeftClick();
                    Thread.Sleep(300);
                    foreach (int key in Hero[HeroName])
                    {
                        DM.KeyPress(key);
                    }
                    DM.MoveTo(370, 163);
                    Thread.Sleep(500);
                    DM.LeftClick();
                }
            }
        }
Example #3
0
 public void Start()
 {
     status = true;
     ProgressChanged(this, status);
     tokenSource = new CancellationTokenSource();
     var token = tokenSource.Token;
     var task  = Task.Factory.StartNew(() => {
         int hwnd = dm.FindWindow("Heroes of the Storm", "");
         dm.BindWindow(hwnd, "gdi", "windows", "windows", 0);
         for (int i = 0; i < count; i++)
         {
             string[] words = phrase.Split('#');
             foreach (var word in words)
             {
                 if (token.IsCancellationRequested)
                 {
                     Console.WriteLine("Abort mission success!");
                     return;
                 }
                 int ret1 = dm.SendString(hwnd, $"{word}");
                 if (ret1 == 0)
                 {
                     MessageBox.Show("失败");
                     break;
                 }
                 dm.KeyPress(13); // Enter
                 Thread.Sleep(interval);
                 Console.WriteLine(status);
             }
         }
         status = false;
         ProgressChanged(this, status);
     }, tokenSource.Token);
     //tokenSource.Cancel();
 }
Example #4
0
        /// <summary>
        /// 开始运行脚本
        /// </summary>
        private void StartGame()
        {
            if (m_process != null)
            {
                m_process.Close();
                m_process.Kill();
                m_process = null;
            }

            m_process = Process.Start(new ProcessStartInfo
            {
                UseShellExecute = false,
                FileName        = m_programPath
            });

            var result = Login();

            if (!result)
            {
                // 启动失败,等待重启
                State = RunningState.Stopped;
                return;
            }

            // 设置开始时间
            StartTime = DateTime.Now;

            // 获取新窗口句柄
            m_dmsoft = DMFactory.Instance.CreateDMSoft();
            while (true)
            {
                var handle = m_dmsoft.EnumWindowByProcessId(m_process.Id, "", "MacromediaFlashPlayerActiveX", 2);
                WxLog.Debug($"AppEntity.StartGame Handl <{handle}>");
                var hs = handle.Split(',');
                foreach (var h in hs)
                {
                    try
                    {
                        var it = int.Parse(h);
                        m_dmsoft.BindWindow(it, "gdi", "windows", "windows", 101);
                        var title = m_dmsoft.GetWindowClass(it);
                        WxLog.Debug($"AppEntity.StartGame {title}");
                    }
                    catch
                    {
                    }
                }

                Thread.Sleep(10000);
            }
        }
Example #5
0
        public static bool BindWindow()
        {
            dmsoft dm = GetDm();

            hwnd = dm.FindWindow("", "poi");
            if (hwnd == 0)
            {
                Outputs.Log("未找到poi浏览器!");
                return(false);
            }
            Outputs.Log("poi窗口句柄为:" + hwnd.ToString());
            int res = dm.BindWindow(hwnd, "normal", "windows", "windows", 0);

            if (res != 1)
            {
                Outputs.Log("窗口绑定失败");
                return(false);
            }
            Outputs.Log("窗口绑定成功");
            return(true);
        }
Example #6
0
 /// <summary>
 /// 为窗口绑定独立的dm对象,没有为窗口对象绑定dm的话,窗口中调用键鼠和图像识别将是对整个屏幕操作。
 /// 如果绑定的句柄为0或-1,直接抛错。
 /// </summary>
 /// <param name="dm"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public bool BindingDmsoft(dmsoft dm, BindingInfo info)
 {
     this.dm = dm;
     if (Hwnd <= 0)
         throw new InvalidHandleException(Hwnd);
     int result = dm.BindWindow(this.Hwnd, info.Display.ToString(), info.Mouse.ToString(), info.Keyboard.ToString(), (int)info.Mode);
     IsBinding = result == 1 ? true : false;
     return IsBinding;
 }
Example #7
0
 /// <summary>
 /// 通用窗口绑定方法
 /// </summary>
 /// <param name="dm"></param>
 /// <param name="hwnd"></param>
 public void BindWindow(dmsoft dm, int hwnd)
 {
     dm.BindWindow(hwnd, "gdi", "windows", "windows", 101);
 }
Example #8
0
 public void BindWindow(int hwnd, string display, string mouse, string keypad, int mode)
 {
     dm.BindWindow(hwnd, display, mouse, keypad, mode);
     this.hwnd = hwnd;
 }
        static void Main(string[] args)
        {
            DM.SetPath(Environment.CurrentDirectory + @"\Image");
            var hwnd = DM.GetMousePointWindow();

            DM.BindWindow(hwnd, "normal", "normal", "dx", 0);


            while (true)
            {
                int keyState = DM.GetKeyState(162);
                //ctrl :162 1:49 2:50 3:51
                if (DM.GetKeyState(162) == 1)
                {
                    //Red Card
                    if (DM.GetKeyState(49) == 1)
                    {
                        string IsRed;
                        Thread.Sleep(500);
                        DM.KeyPress((int)Keys.W);
                        for (int i = 0; i < 30; i++)
                        {
                            IsRed = DM.FindPicE(792, 939, 861, 1025, "Card_R.bmp|Card_Y.bmp|Card_B.bmp", "000000", 0.5, 0).Split('|')[0];
                            if (IsRed == "0")
                            {
                                DM.KeyPress((int)Keys.W);
                                break;
                            }
                            Thread.Sleep(100);
                        }
                        continue;
                    }
                    //Yellow Card
                    else if (DM.GetKeyState(50) == 1)
                    {
                        string IsYow;
                        Thread.Sleep(500);
                        DM.KeyPress((int)Keys.W);
                        for (int i = 0; i < 30; i++)
                        {
                            IsYow = DM.FindPicE(792, 939, 861, 1025, "Card_R.bmp|Card_Y.bmp|Card_B.bmp", "000000", 0.5, 0).Split('|')[0];
                            if (IsYow == "1")
                            {
                                DM.KeyPress((int)Keys.W);
                                break;
                            }
                            Thread.Sleep(100);
                        }
                        continue;
                    }
                    //Blue Card
                    else if (DM.GetKeyState(51) == 1)
                    {
                        string IsBlue;
                        Thread.Sleep(500);
                        DM.KeyPress((int)Keys.W);
                        for (int i = 0; i < 30; i++)
                        {
                            IsBlue = DM.FindPicE(792, 939, 861, 1025, "Card_R.bmp|Card_Y.bmp|Card_B.bmp", "000000", 0.5, 0).Split('|')[0];
                            if (IsBlue == "2")
                            {
                                DM.KeyPress((int)Keys.W);
                                break;
                            }
                            Thread.Sleep(100);
                        }
                        continue;
                    }
                }
            }
        }
Example #10
0
 /// <summary>
 /// 绑定指定的窗口,并指定这个窗口的屏幕颜色获取方式,鼠标仿真模式,键盘仿真模式,以及模式设定,高级用户可以参考BindWindowEx更加灵活强大
 /// </summary>
 /// <param name="dmsoft"></param>
 /// <param name="hwnd">窗口句柄</param>
 /// <param name="bindWindow"></param>
 /// <returns>如果返回false,可以调用GetLastError来查看具体失败错误码,帮助分析问题.</returns>
 public static bool BindWindow(this dmsoft dmsoft, int hwnd, BindWindow bindWindow)
 {
     return(dmsoft.BindWindow(hwnd, bindWindow.Display, bindWindow.Mouse, bindWindow.Keypad, bindWindow.Mode) == 1);
 }
Example #11
0
 public static int BindWindowByCustom(this dmsoft dm, int hwnd)
 {
     return(dm.BindWindow(hwnd, "dx2", "windows", "windows", 1));
 }
Example #12
0
 public int BindWindow(int hwnd, string display, string mouse, string keypad, int mode)
 {
     return(dm.BindWindow(hwnd, display, mouse, keypad, mode));
 }
Example #13
0
 public int BindWindow(int hwnd, string display = "gdi", string mouse = "windows", string keypad = "windows", int mode = 0)
 {
     return(dm.BindWindow(hwnd, display, mouse, keypad, mode));
 }