Пример #1
0
        private void Tick(object sender, EventArgs e)
        {
            try
            {
                _keyboard.Poll();
            }
            catch (Exception)
            {
                Finish();
                ControllerDisconnected?.Invoke(this, EventArgs.Empty);
                return;
            }

            ControllerStateBuilder outState = new ControllerStateBuilder();
            KeyboardState          state    = _keyboard.GetCurrentState();

            foreach (string key in Enum.GetNames(typeof(Key)))
            {
                outState.SetButton(key, false);
            }

            for (int i = 0; i < state.PressedKeys.Count; i++)
            {
                outState.SetButton(state.PressedKeys[i].ToString(), true);
            }

            ControllerStateChanged?.Invoke(this, outState.Build());
        }
        /// <summary>
        /// Raises the <see cref="ControllerDisconnected"/> event.
        /// </summary>
        /// <param name="inEventArgs">The event data.</param>
        internal static void onControllerDisconnected(ControllerConnectionEventArgs inEventArgs)
        {
            // Written, 16.07.2018

            if (ControllerDisconnected != null)
            {
                ControllerDisconnected.Invoke(null, inEventArgs);
            }
        }
Пример #3
0
        private void Tick(object sender, EventArgs e)
        {
            try
            {
                _keyboard.Poll();
                _mouse.Poll();
            }
            catch (SharpDXException)
            {
                Finish();
                ControllerDisconnected?.Invoke(this, EventArgs.Empty);
                return;
            }

            ControllerStateBuilder outState   = new ControllerStateBuilder();
            KeyboardState          state      = _keyboard.GetCurrentState();
            MouseState             mouseState = _mouse.GetCurrentState();

            SignalTool.SetPCMouseProperties(mouseState.X / 255.0f, -mouseState.Y / 255.0f, mouseState.X, mouseState.Y, outState, 1.0f);

            if (mouseState.Z > 0)
            {
                outState.SetButton("MouseScrollUp", true);
                outState.SetButton("MouseScrollDown", false);
            }
            else if (mouseState.Z < 0)
            {
                outState.SetButton("MouseScrollDown", true);
                outState.SetButton("MouseScrollUp", false);
            }
            else
            {
                outState.SetButton("MouseScrollDown", false);
                outState.SetButton("MouseScrollUp", false);
            }

            for (int i = 0; i < MOUSE_BUTTONS.Length; ++i)
            {
                outState.SetButton(MOUSE_BUTTONS[i], mouseState.Buttons[i]);
            }

            foreach (string key in Enum.GetNames(typeof(Key)))
            {
                outState.SetButton(key, false);
            }

            for (int i = 0; i < state.PressedKeys.Count; i++)
            {
                outState.SetButton(state.PressedKeys[i].ToString(), true);
            }

            ControllerStateChanged?.Invoke(this, outState.Build());
        }
Пример #4
0
        private void Tick(object sender, EventArgs e)
        {
            try
            {
                _joystick.Poll();
            }
            catch (SharpDXException)
            {
                Finish();
                ControllerDisconnected?.Invoke(this, EventArgs.Empty);
                return;
            }

            ControllerStateBuilder outState = new ControllerStateBuilder();
            JoystickState          state    = _joystick.GetCurrentState();

            for (int i = 0; i < _joystick.Capabilities.ButtonCount; ++i)
            {
                outState.SetButton("b" + i.ToString(CultureInfo.CurrentCulture), state.Buttons[i]);
            }

            int[] pov = state.PointOfViewControllers;

            outState.SetButton("up", false);
            outState.SetButton("right", false);
            outState.SetButton("down", false);
            outState.SetButton("left", false);

            if (pov != null && pov.Length > 0 && pov[0] >= 0)
            {
                outState.SetButton("up", pov[0] > OctantAngle(6) || pov[0] < OctantAngle(1));
                outState.SetButton("right", pov[0] > OctantAngle(0) && pov[0] < OctantAngle(3));
                outState.SetButton("down", pov[0] > OctantAngle(2) && pov[0] < OctantAngle(5));
                outState.SetButton("left", pov[0] > OctantAngle(4) && pov[0] < OctantAngle(7));
            }
            else if (_joystick.Information.ProductName == "8Bitdo SF30 Wireless Controller") // For SN30
            {
                outState.SetButton("up", (float)state.Y / RANGE == -1.0);
                outState.SetButton("down", (float)state.Y / RANGE == 1.0);
                outState.SetButton("left", (float)state.X / RANGE == -1.0);
                outState.SetButton("right", (float)state.X / RANGE == 1.0);
            }

            outState.SetAnalog("x", (float)state.X / RANGE, state.X);
            outState.SetAnalog("y", (float)state.Y / RANGE, state.Y);
            outState.SetAnalog("z", (float)state.Z / RANGE, state.Z);
            outState.SetAnalog("rx", (float)state.RotationX / RANGE, state.RotationX);
            outState.SetAnalog("ry", (float)state.RotationY / RANGE, state.RotationY);
            outState.SetAnalog("rz", (float)state.RotationZ / RANGE, state.RotationZ);

            ControllerStateChanged?.Invoke(this, outState.Build());
        }
        public static void Initialize(Game game, int ps4PollIntervalInFrames)
        {
            game.Exiting += (s, e) =>
            {
                foreach (var controller in _controllers)
                {
                    //Make sure any native handles are cleaned up.
                    if (controller is Ps4Controller ps4)
                    {
                        ps4.Close();
                    }
                }
            };

            for (var i = 0; i < GamePad.MaximumGamePadCount; i++)
            {
                var controller = new XInputController(i);
                _controllers.Add(controller);
                controller.Connected    += (s, e) => ControllerConnected(null, (IController)s);
                controller.Disconnected += (s, e) => ControllerDisconnected(null, (IController)s);
            }

#if Windows
            _pollInterval = ps4PollIntervalInFrames;
            if (_pollInterval > 0)
            {
                _ps4Manager = new Ps4Manager((controller) =>
                {
                    var index = _controllers.Add(controller);
                    controller.SetIndex(index);
                    ControllerConnected?.Invoke(null, controller);
                    controller.Disconnected += (s, e) =>
                    {
                        var c = (IController)s;
                        ControllerDisconnected?.Invoke(null, c);
                        _controllers.FastRemove(c.Index);
                    };
                }, false);
                _frames = _pollInterval;
            }
#endif
        }
Пример #6
0
        private void Tick(object sender, EventArgs e)
        {
            XInputState state = new XInputState();

            if (NativeMethods.XInputGetState(_id, ref state) > 0)
            {
                ControllerDisconnected?.Invoke(this, EventArgs.Empty);
                Finish();
                return;
            }

            ControllerStateBuilder outState = new ControllerStateBuilder();

            outState.SetButton("a", (state.wButtons & 0x1000) != 0);
            outState.SetButton("b", (state.wButtons & 0x2000) != 0);
            outState.SetButton("x", (state.wButtons & 0x4000) != 0);
            outState.SetButton("y", (state.wButtons & 0x8000) != 0);
            outState.SetButton("up", (state.wButtons & 0x0001) != 0);
            outState.SetButton("down", (state.wButtons & 0x0002) != 0);
            outState.SetButton("left", (state.wButtons & 0x0004) != 0);
            outState.SetButton("right", (state.wButtons & 0x0008) != 0);
            outState.SetButton("start", (state.wButtons & 0x0010) != 0);
            outState.SetButton("back", (state.wButtons & 0x0020) != 0);
            outState.SetButton("l3", (state.wButtons & 0x0040) != 0);
            outState.SetButton("r3", (state.wButtons & 0x0080) != 0);
            outState.SetButton("l", (state.wButtons & 0x0100) != 0);
            outState.SetButton("r", (state.wButtons & 0x0200) != 0);

            outState.SetAnalog("lstick_x", (float)state.sThumbLX / 32768);
            outState.SetAnalog("lstick_y", (float)state.sThumbLY / 32768);
            outState.SetAnalog("rstick_x", (float)state.sThumbRX / 32768);
            outState.SetAnalog("rstick_y", (float)state.sThumbRY / 32768);
            outState.SetAnalog("trig_l", (float)state.bLeftTrigger / 255);
            outState.SetAnalog("trig_r", (float)state.bRightTrigger / 255);

            ControllerStateChanged?.Invoke(this, outState.Build());
        }
Пример #7
0
 private void BaseControllerReader_ControllerDisconnected(object sender, EventArgs e)
 {
     ControllerDisconnected?.Invoke(this, e);
 }
Пример #8
0
 private void SerialMonitor_Disconnected(object sender, EventArgs e)
 {
     Finish();
     ControllerDisconnected?.Invoke(this, EventArgs.Empty);
 }