Exemplo n.º 1
0
        public static void Initialize(MainWindow mw)
        {
            KeyInput.Initialize(mw);
            //IPCKeyInput.Initialize();
            GamePad.Initialize(mw);
            GamePad360.Initialize(mw);

            Instance = new Input();
        }
Exemplo n.º 2
0
        public static void Initialize(MainWindow mw)
        {
            KeyInput.Initialize(mw);
            GamePad.Initialize(mw);
            GamePad360.Initialize(mw);

            Instance          = new Input();
            Instance.main     = mw;
            Instance.GotFocus = true;
        }
Exemplo n.º 3
0
        void UpdateThreadProc()
        {
            for (;;)
            {
                if (AbortThread == true)
                {
                    break;
                }


                var keyEvents = KeyInput.Update(); //.Concat(IPCKeyInput.Update());
                GamePad.UpdateAll();
                GamePad360.UpdateAll();

                //this block is going to massively modify data structures that the binding method uses, so we have to lock it all
                lock (this)
                {
                    _NewEvents.Clear();

                    //analyze keys
                    foreach (var ke in keyEvents)
                    {
                        HandleButton(ke.Key.ToString(), ke.Pressed);
                    }

                    lock (FloatValues)
                    {
                        //FloatValues.Clear();

                        //analyze xinput
                        for (int i = 0; i < GamePad360.Devices.Count; i++)
                        {
                            var    pad   = GamePad360.Devices[i];
                            string xname = "X" + (pad.PlayerNumber) + " ";
                            for (int b = 0; b < pad.NumButtons; b++)
                            {
                                //HandleButton(xname + pad.ButtonName(b), pad.Pressed(b));
                                HandleButton(pad.ButtonName(b), pad.Pressed(b));
                            }
                            foreach (var sv in pad.GetFloats())
                            {
                                string n = xname + sv.Item1;
                                float  f = sv.Item2;
                                if (trackdeltas)
                                {
                                    FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
                                }
                                FloatValues[n] = f;
                            }
                        }

                        //analyze joysticks
                        for (int i = 0; i < GamePad.Devices.Count; i++)
                        {
                            var    pad   = GamePad.Devices[i];
                            string jname = "J" + (i + 1) + " ";

                            for (int b = 0; b < pad.NumButtons; b++)
                            {
                                //HandleButton(jname + pad.ButtonName(b), pad.Pressed(b));
                                HandleButton(pad.ButtonName(b), pad.Pressed(b));
                                string na = pad.ButtonName(b);
                            }

                            foreach (var sv in pad.GetFloats())
                            {
                                //string n = jname + sv.Item1;
                                string n = sv.Item1;
                                float  f = sv.Item2;
                                //if (n == "J5 RotationZ")
                                //	System.Diagnostics.Debugger.Break();
                                if (trackdeltas)
                                {
                                    FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
                                }
                                FloatValues[n] = f;
                            }
                        }

                        // analyse moose
                        // other sorts of mouse api (raw input) could easily be added as a separate listing under a different class

                        /*
                         *                      if (WantingMouseFocus.Contains(System.Windows.Forms.Form.ActiveForm))
                         *                      {
                         *                              var P = System.Windows.Forms.Control.MousePosition;
                         *                              if (trackdeltas)
                         *                              {
                         *                                      // these are relative to screen coordinates, but that's not terribly important
                         *                                      FloatDeltas["WMouse X"] += Math.Abs(P.X - FloatValues["WMouse X"]) * 50;
                         *                                      FloatDeltas["WMouse Y"] += Math.Abs(P.Y - FloatValues["WMouse Y"]) * 50;
                         *                              }
                         *                              // coordinate translation happens later
                         *                              FloatValues["WMouse X"] = P.X;
                         *                              FloatValues["WMouse Y"] = P.Y;
                         *
                         *                              var B = System.Windows.Forms.Control.MouseButtons;
                         *                              HandleButton("WMouse L", (B & System.Windows.Forms.MouseButtons.Left) != 0);
                         *                              HandleButton("WMouse C", (B & System.Windows.Forms.MouseButtons.Middle) != 0);
                         *                              HandleButton("WMouse R", (B & System.Windows.Forms.MouseButtons.Right) != 0);
                         *                              HandleButton("WMouse 1", (B & System.Windows.Forms.MouseButtons.XButton1) != 0);
                         *                              HandleButton("WMouse 2", (B & System.Windows.Forms.MouseButtons.XButton2) != 0);
                         *                      }
                         *                      else
                         *                      {
                         *                              //dont do this: for now, it will interfere with the virtualpad. dont do something similar for the mouse position either
                         *                              //unpress all buttons
                         *                              //HandleButton("WMouse L", false);
                         *                              //HandleButton("WMouse C", false);
                         *                              //HandleButton("WMouse R", false);
                         *                              //HandleButton("WMouse 1", false);
                         *                              //HandleButton("WMouse 2", false);
                         *                      }
                         */
                    }

                    //bool swallow = !GlobalWin.MainForm.AllowInput(false);

                    foreach (var ie in _NewEvents)
                    {
                        //events are swallowed in some cases:
                        if (ie.LogicalButton.Alt) // && !GlobalWin.MainForm.AllowInput(true))
                        {
                        }
                        else if (ie.EventType == InputEventType.Press) // && swallow)
                        {
                        }
                        else
                        {
                            EnqueueEvent(ie);
                        }
                    }
                } //lock(this)

                //arbitrary selection of polling frequency:
                Thread.Sleep(10);
            }
        }
Exemplo n.º 4
0
 public static void ReInitGamepads(MainWindow mw)
 {
     GamePad.Initialize(mw);
     GamePad360.Initialize(mw);
 }