Exemple #1
0
        public static void Initialize()
        {
#if WINDOWS
            KeyInput.Initialize();
            IPCKeyInput.Initialize();
            GamePad.Initialize();
            GamePad360.Initialize();
#endif
            Instance = new Input();
        }
Exemple #2
0
        public static void Initialize()
        {
            if (PlatformLinkedLibSingleton.RunningOnUnix)
            {
                OTK_Keyboard.Initialize();
//				OTK_Gamepad.Initialize();
            }
            else
            {
                KeyInput.Initialize();
                IPCKeyInput.Initialize();
                GamePad.Initialize();
                GamePad360.Initialize();
            }
            Instance = new Input();
        }
Exemple #3
0
 public static void Initialize(Control parent)
 {
     if (OSTailoredCode.IsUnixHost)
     {
         OTK_Keyboard.Initialize();
         OTK_GamePad.Initialize();
     }
     else
     {
         KeyInput.Initialize(parent);
         IPCKeyInput.Initialize();
         GamePad.Initialize(parent);
         GamePad360.Initialize();
     }
     Instance = new Input();
 }
Exemple #4
0
        public static void Initialize()
        {
            if (OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows)
            {
                KeyInput.Initialize();
                IPCKeyInput.Initialize();
                GamePad.Initialize();
                GamePad360.Initialize();
            }
            else
            {
                OTK_Keyboard.Initialize();
//				OTK_Gamepad.Initialize();
            }
            Instance = new Input();
        }
Exemple #5
0
        public static void Initialize()
        {
            if (Global.RunningOnUnix)
            {
                OTK_Keyboard.Initialize();
//				OTK_Gamepad.Initialize();
            }
            else
            {
                KeyInput.Initialize();
                IPCKeyInput.Initialize();
                GamePad.Initialize();
                GamePad360.Initialize();
            }
            Instance = new Input();
        }
Exemple #6
0
 public static void Initialize()
 {
     if (OSTailoredCode.IsWindows())
     {
         KeyInput.Initialize();
         IPCKeyInput.Initialize();
         GamePad.Initialize();
         GamePad360.Initialize();
     }
     else
     {
         OTK_Keyboard.Initialize();
         OTK_GamePad.Initialize();
     }
     Instance = new Input();
 }
Exemple #7
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
                        {
#if false // 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, InputFocus.Mouse);
                            HandleButton("WMouse C", false, InputFocus.Mouse);
                            HandleButton("WMouse R", false, InputFocus.Mouse);
                            HandleButton("WMouse 1", false, InputFocus.Mouse);
                            HandleButton("WMouse 2", false, InputFocus.Mouse);
#endif
                        }
                    }

                    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);
            }
        }
Exemple #8
0
        void UpdateThreadProc()
        {
            for (; ;)
            {
                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" + (i + 1) + " ";
                            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
                        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));
                            }
                            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);
                        }
                    }

                    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);
            }
        }
 public IEnumerable <KeyEvent> ProcessHostKeyboards() => KeyInput.Update().Concat(IPCKeyInput.Update());
 public void FirstInitAll(IntPtr mainFormHandle)
 {
     KeyInput.Initialize(mainFormHandle);
     IPCKeyInput.Initialize();
     ReInitGamepads(mainFormHandle);
 }
Exemple #11
0
        void UpdateThreadProc()
        {
            while (true)
            {
                var keyEvents = OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows
                                        ? KeyInput.Update().Concat(IPCKeyInput.Update())
                                        : OTK_Keyboard.Update();
                if (OSTailoredCode.CurrentOS == OSTailoredCode.DistinctOS.Windows)
                {
                    GamePad.UpdateAll();
                    GamePad360.UpdateAll();
                }
                else
                {
                    //TODO
                }

                //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 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;
                            }
                        }

                        // 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, InputFocus.Mouse);
                            HandleButton("WMouse C", (B & System.Windows.Forms.MouseButtons.Middle) != 0, InputFocus.Mouse);
                            HandleButton("WMouse R", (B & System.Windows.Forms.MouseButtons.Right) != 0, InputFocus.Mouse);
                            HandleButton("WMouse 1", (B & System.Windows.Forms.MouseButtons.XButton1) != 0, InputFocus.Mouse);
                            HandleButton("WMouse 2", (B & System.Windows.Forms.MouseButtons.XButton2) != 0, InputFocus.Mouse);
                        }
                        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.
                    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))
                        {
                        }
                        else if (ie.EventType == InputEventType.Press && ShouldSwallow(allowInput, ie))
                        {
                        }
                        else
                        {
                            EnqueueEvent(ie);
                        }
                    }
                }                 //lock(this)

                //arbitrary selection of polling frequency:
                Thread.Sleep(10);
            }
        }