Пример #1
0
 public IEnumerable <KeyEvent> ProcessHostKeyboards() => KeyInput.Update().Concat(IPCKeyInput.Update());
Пример #2
0
 public void FirstInitAll(IntPtr mainFormHandle)
 {
     KeyInput.Initialize(mainFormHandle);
     IPCKeyInput.Initialize();
     ReInitGamepads(mainFormHandle);
 }
Пример #3
0
        private void UpdateThreadProc()
        {
            while (true)
            {
#if true
                var keyEvents = OTK_Keyboard.Update();
                OTK_GamePad.UpdateAll();
#else
                var keyEvents = OSTailoredCode.IsUnixHost
                                        ? OTK_Keyboard.Update()
                                        : KeyInput.Update().Concat(IPCKeyInput.Update());
                if (OSTailoredCode.IsUnixHost)
                {
                    OTK_GamePad.UpdateAll();
                }
                else
                {
                    GamePad.UpdateAll();
                    GamePad360.UpdateAll();
                }
#endif

                //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, InputFocus.Keyboard);
                    }

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

                        // analyze OpenTK xinput (or is it libinput?)
                        foreach (var pad in OTK_GamePad.EnumerateDevices())
                        {
                            foreach (var but in pad.buttonObjects)
                            {
                                HandleButton(pad.InputNamePrefix + but.ButtonName, but.ButtonAction(), InputFocus.Pad);
                            }
                            foreach (var sv in pad.GetFloats())
                            {
                                var n = $"{pad.InputNamePrefix}{sv.Item1} Axis";
                                var f = sv.Item2;
                                if (_trackDeltas)
                                {
                                    _floatDeltas[n] += Math.Abs(f - _floatValues[n]);
                                }
                                _floatValues[n] = f;
                            }
                        }

#if false
                        // analyze xinput
                        foreach (var pad in GamePad360.EnumerateDevices())
                        {
                            string xName = $"X{pad.PlayerNumber} ";
                            for (int b = 0; b < pad.NumButtons; b++)
                            {
                                HandleButton(xName + pad.ButtonName(b), pad.Pressed(b), InputFocus.Pad);
                            }
                            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
                        foreach (var pad in GamePad.EnumerateDevices())
                        {
                            string jName = $"J{pad.PlayerNumber} ";
                            for (int b = 0; b < pad.NumButtons; b++)
                            {
                                HandleButton(jName + pad.ButtonName(b), pad.Pressed(b), InputFocus.Pad);
                            }
                            foreach (var sv in pad.GetFloats())
                            {
                                string n = jName + 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;
                            }
                        }
#endif

                        // analyze moose
                        // other sorts of mouse api (raw input) could easily be added as a separate listing under a different class
                        if (_wantingMouseFocus.Contains(Form.ActiveForm))
                        {
                            var mousePos = Control.MousePosition;
                            if (_trackDeltas)
                            {
                                // these are relative to screen coordinates, but that's not terribly important
                                _floatDeltas["WMouse X"] += Math.Abs(mousePos.X - _floatValues["WMouse X"]) * 50;
                                _floatDeltas["WMouse Y"] += Math.Abs(mousePos.Y - _floatValues["WMouse Y"]) * 50;
                            }
                            // coordinate translation happens later
                            _floatValues["WMouse X"] = mousePos.X;
                            _floatValues["WMouse Y"] = mousePos.Y;

                            var mouseBtns = Control.MouseButtons;
                            HandleButton("WMouse L", (mouseBtns & MouseButtons.Left) != 0, InputFocus.Mouse);
                            HandleButton("WMouse C", (mouseBtns & MouseButtons.Middle) != 0, InputFocus.Mouse);
                            HandleButton("WMouse R", (mouseBtns & MouseButtons.Right) != 0, InputFocus.Mouse);
                            HandleButton("WMouse 1", (mouseBtns & MouseButtons.XButton1) != 0, InputFocus.Mouse);
                            HandleButton("WMouse 2", (mouseBtns & MouseButtons.XButton2) != 0, InputFocus.Mouse);
                        }
                        else
                        {
                            // don't do this: for now, it will interfere with the virtualpad. don't 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);
                        }
                    }

                    if (_newEvents.Count != 0)
                    {
                        //WHAT!? WE SHOULD NOT BE SO NAIVELY TOUCHING MAINFORM FROM THE INPUTTHREAD. ITS BUSY RUNNING.
                        AllowInput allowInput = GlobalWin.MainForm.AllowInput(false);

                        foreach (var ie in _newEvents)
                        {
                            //events are swallowed in some cases:
                            if (ie.LogicalButton.Alt && ShouldSwallow(GlobalWin.MainForm.AllowInput(true), ie))
                            {
                                continue;
                            }
                            if (ie.EventType == InputEventType.Press && ShouldSwallow(allowInput, ie))
                            {
                                continue;
                            }

                            EnqueueEvent(ie);
                        }
                    }

                    _ignoreEventsNextPoll = false;
                }                 //lock(this)

                //arbitrary selection of polling frequency:
                Thread.Sleep(10);
            }
        }
Пример #4
0
 public void DeInitAll()
 {
     KeyInput.Cleanup();
     GamePad.Cleanup();
 }
Пример #5
0
        void UpdateThreadProc()
        {
            while (true)
            {
                var keyEvents = PlatformLinkedLibSingleton.RunningOnUnix
                                        ? OTK_Keyboard.Update()
                                        : KeyInput.Update().Concat(IPCKeyInput.Update());
                if (PlatformLinkedLibSingleton.RunningOnUnix)
                {
                    OTK_GamePad.UpdateAll();
                }
                else
                {
                    GamePad.UpdateAll();
                    GamePad360.UpdateAll();
                    //OTK_GamePad.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 OTK
                        foreach (var pad in OTK_GamePad.EnumerateDevices())
                        {
                            string cType = pad.MappedGamePad ? "X" : "J";
                            string xname = cType + pad.ID + " ";

                            foreach (var but in pad.buttonObjects)
                            {
                                HandleButton(xname + but.ButtonName, but.ButtonAction());
                            }

                            foreach (var sv in pad.GetFloats())
                            {
                                string n = xname + sv.Item1 + " Axis";
                                float  f = sv.Item2;
                                if (trackdeltas)
                                {
                                    FloatDeltas[n] += Math.Abs(f - FloatValues[n]);
                                }
                                FloatValues[n] = f;
                            }
                        }

                        //analyze xinput
                        foreach (var pad in GamePad360.EnumerateDevices())
                        {
                            string xname = "X" + pad.PlayerNumber + " ";
                            for (int b = 0; b < pad.NumButtons; b++)
                            {
                                HandleButton(xname + 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
                        foreach (var pad in GamePad.EnumerateDevices())
                        {
                            string jname = "J" + pad.PlayerNumber + " ";
                            for (int b = 0; b < pad.NumButtons; b++)
                            {
                                HandleButton(jname + pad.ButtonName(b), pad.Pressed(b));
                            }
                            foreach (var sv in pad.GetFloats())
                            {
                                string n = jname + 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);
                        }
                    }

                    //WHAT!? WE SHOULD NOT BE SO NAIVELY TOUCHING MAINFORM FROM THE INPUTTHREAD. ITS BUSY RUNNING.
                    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);
            }
        }