示例#1
0
        /// <summary>
        /// Handles keyboard input.
        /// </summary>
        /// <param name="clickData"></param>
        /// <param name="time"></param>
        public static void UpdateKeyboardInput(GameTime time)
        {
            GetChanges(out List <Keys> pressed, out List <Keys> down, out List <Keys> released);

            if (pressed.Count > 0)
            {
                int length = pressed.Count;
                for (int i = 0; i < length; i++)
                {
                    KeysPressed?.Invoke(null, pressed[i]);
                }
            }

            if (down.Count > 0)
            {
                int length = down.Count;
                for (int i = 0; i < length; i++)
                {
                    KeysDown?.Invoke(null, down[i]);
                }
            }

            if (released.Count > 0)
            {
                int length = released.Count;
                for (int i = 0; i < length; i++)
                {
                    KeysReleased?.Invoke(null, released[i]);
                }
            }

            KeyboardState keyboardState = Keyboard.GetState();

            Modifiers = KeyboardModifiers.None;

            if (keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl))
            {
                Modifiers |= KeyboardModifiers.Control;
            }

            if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift))
            {
                Modifiers |= KeyboardModifiers.Shift;
            }

            if (keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt))
            {
                Modifiers |= KeyboardModifiers.Alt;
            }
        }
示例#2
0
 /// <summary>
 /// Invoke the KeyPressed event.
 /// </summary>
 /// <param name="keys"></param>
 public static void InvokeKeysPressed(List <Keys> keys)
 {
     KeysPressed?.Invoke(null, new KeyboardEventArgs(keys));
 }