Пример #1
0
        public void Go()
        {
            if (Connect())
            {
                m_fXimRunning = true;

                // Get thing set up.
                DxInputManager dxInputManager = DxInputManager.Instance;

                System.Drawing.Point cursorPosition = Cursor.Position;
                Xim.Input input = new Xim.Input();
                Xim.Input startState = new Xim.Input();
                ximDyn.SetMode((bool)m_autoAnalogDisconnect.Value ? Xim.Mode.AutoAnalogDisconnect : Xim.Mode.None);
                ximDyn.SendInput(ref input, 0);
                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                bool bTextMode = false;
                bool done = false;

                watch.Start();
                Cursor.Hide();

                //

                m_textMode.Value = false;
                TimeSpan prevTick = watch.Elapsed;
                Log("Press ESCAPE to stop X2 processing");

                dxInputManager.Acquire();
                if (dxInputManager.ControllersPresent())
                    m_eventManager.QueueAnalogJoyBinds();

                // Main Processing Loop
                while (!done)
                {
                    System.Windows.Forms.Application.DoEvents();
                    double wait = (bool)m_textMode.Value ? (1000 / (double)m_textModeRate.Value) : (1000 / (double)m_rate.Value);
                    while (watch.Elapsed.TotalMilliseconds - prevTick.TotalMilliseconds < wait)
                    {
                        if (m_form.ContainsFocus)
                        {
                            Cursor.Position = cursorPosition;
                        }
                        System.Threading.Thread.Sleep(2);
                    }

                    if (!m_form.ContainsFocus)
                    {
                        m_inputManager.ClearInput();
                        System.Threading.Thread.Sleep(100);
                        continue;
                    }
                    else
                    {
                        dxInputManager.PollAndProcess(!(bool)m_textMode.Value);
                    }

                    input.CopyFrom(startState);
                    TimeSpan thisTick = watch.Elapsed;
                    double delay = thisTick.TotalMilliseconds - prevTick.TotalMilliseconds;
                    prevTick = thisTick;

                    if (delay > 1000)
                        continue;

                    if ((bool)m_textMode.Value)
                    {
                        if (!bTextMode)
                        {
                            Log("Entering Text Mode. Press END to exit text mode" + Environment.NewLine);
                            bTextMode = true;
                        }
                        m_textModeManager.ProcessOutput(delay, ref input, ref startState);

                        if (m_inputManager.IsKeyDown(DxI.Key.End))
                        {
                            m_textModeManager.Reset();
                            m_textMode.Value = false;
                            Log("Exiting Text Mode");
                        }

                        bTextMode = (bool)m_textMode.Value;
                    }
                    else
                    {
                        bTextMode = (bool)m_textMode.Value;

                        m_eventManager.ProcessEvents(delay, ref input, ref startState);
                        if ((bool)m_useXimApiMouseMath.Value)
                        {
                            this.mouseMath.ProcessMouseMovement(ref input, ref startState);

                        }
                        else
                        {
                            //this.betaMouseMath.XSoftMouseMovement(delay, ref input, ref startState);
                            this.mouseMath.XSoftMouseMovement(ref input, ref startState);
                        }
                        m_eventManager.ProcessLinks(delay, ref input, ref startState);
                    }

                    if ( m_inputManager.IsKeyDown(DxI.Key.Escape))
                    {
                        break;
                    }

                    if (m_form.ContainsFocus)
                    {
                        m_form.UpdateOutputView(input);
                        ximDyn.SendInput(ref input, 1);
                    }
                    else
                    {
                        ximDyn.SendInput(ref m_blankInput, 1);
                    }
                }

                // Shutdown and clear events and input
                m_form.UpdateOutputView(m_blankInput);
                m_inputManager.ClearInput();
                m_eventManager.ClearEvents();
                DxInputManager.Instance.Unaquire();
                m_fXimRunning = false;
                Disconnect();
            }
        }