Пример #1
0
 private void detection()
 {
     while (true)
     {
         if (hwnd != WindowsInfo.GetForegroundWindow())
         {
             Work.Abort();
             isRunning = false;
             break;
         }
     }
 }
Пример #2
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            try
            {
                if (m.Msg == WM_HOTKEY)
                {
                    switch (m.WParam.ToInt32())
                    {
                    case 1:
                        if (chkHotkeyFun.Checked)
                        {
                            hwnd = KeyMouseEvents.GetForegroundWindow();
                            KeyMouseEvents.keyPress(System.Windows.Forms.Keys.F1, 0, hwnd);
                        }
                        if (isRunning)
                        {
                            return;
                        }
                        hwnd = WindowsInfo.FindWindow("D3 Main Window Class", null);
                        if (hwnd == IntPtr.Zero)
                        {
                            MessageBox.Show("找不到Diablo 3視窗");
                            return;
                        }
                        if (hwnd != WindowsInfo.GetForegroundWindow())
                        {
                            MessageBox.Show("Diablo 3並不是前景視窗");
                            return;
                        }
                        if (!chk1.Checked && !chk2.Checked && !chk3.Checked && !chk4.Checked && !chkLeft.Checked && !chkRight.Checked)
                        {
                            MessageBox.Show("請選擇按鍵");
                            return;
                        }
                        isRunning = true;
                        Work      = new System.Threading.Thread(this.doWork);
                        Detector  = new System.Threading.Thread(this.detection);
                        Work.Start();
                        Detector.Start();
                        break;

                    case 2:
                        if (chkHotkeyFun.Checked)
                        {
                            hwnd = KeyMouseEvents.GetForegroundWindow();
                            KeyMouseEvents.keyPress(System.Windows.Forms.Keys.F2, 0, hwnd);
                        }
                        if (isRunning)
                        {
                            Work.Abort();
                            Detector.Abort();
                            //release keyboard and mouse
                            if (chk1.Checked)
                            {
                                KeyMouseEvents.keyPress(System.Windows.Forms.Keys.D1, 0, hwnd);
                            }
                            if (chk2.Checked)
                            {
                                KeyMouseEvents.keyPress(System.Windows.Forms.Keys.D2, 0, hwnd);
                            }
                            if (chk3.Checked)
                            {
                                KeyMouseEvents.keyPress(System.Windows.Forms.Keys.D3, 0, hwnd);
                            }
                            if (chk4.Checked)
                            {
                                KeyMouseEvents.keyPress(System.Windows.Forms.Keys.D4, 0, hwnd);
                            }
                            if (chkLeft.Checked)
                            {
                                KeyMouseEvents.mouseLClick();
                            }
                            if (chkRight.Checked)
                            {
                                KeyMouseEvents.mouseRClick();
                            }
                            isRunning = false;
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace + ": " + ex.Message);
            }
            finally
            {
                base.WndProc(ref m);
            }
        }