예제 #1
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());
        }