Exemplo n.º 1
0
        private void UpdateInputDeviceList()
        {
            _inputDevice.RemoveAll();
            _inputDevice.Append("disabled", "Disabled");
            _inputDevice.SetActiveId("disabled");

            _inputDevice.Append($"keyboard/{KeyboardConfig.AllKeyboardsIndex}", "All keyboards");

            for (int i = 0; i < 20; i++)
            {
                if (KeyboardController.GetKeyboardState(i + 1).IsConnected)
                {
                    _inputDevice.Append($"keyboard/{i + 1}", $"Keyboard/{i + 1}");
                }

                if (GamePad.GetState(i).IsConnected)
                {
                    _inputDevice.Append($"controller/{i}", $"Controller/{i} ({GamePad.GetName(i)})");
                }
            }

            switch (_inputConfig)
            {
            case KeyboardConfig keyboard:
                _inputDevice.SetActiveId($"keyboard/{keyboard.Index}");
                break;

            case ControllerConfig controller:
                _inputDevice.SetActiveId($"controller/{controller.Index}");
                break;
            }
        }
Exemplo n.º 2
0
        private static bool IsAnyKeyPressed(out Key pressedKey, int index)
        {
            KeyboardState keyboardState = KeyboardController.GetKeyboardState(index);

            foreach (Key key in Enum.GetValues(typeof(Key)))
            {
                if (keyboardState.IsKeyDown((OpenTK.Input.Key)key))
                {
                    pressedKey = key;

                    return(true);
                }
            }

            pressedKey = Key.Unbound;

            return(false);
        }