using System.Buffers; using System.Runtime.CompilerServices; namespace Ryujinx.Input { /// /// Represent an emulated keyboard. /// public interface IKeyboard : IGamepad { private static bool[] _keyState; /// /// Check if a given key is pressed on the keyboard. /// /// The key /// True if the given key is pressed on the keyboard bool IsPressed(Key key); /// /// Get a snaphost of the state of the keyboard. /// /// A snaphost of the state of the keyboard. KeyboardStateSnapshot GetKeyboardStateSnapshot(); /// /// Get a snaphost of the state of a keyboard. /// /// The keyboard to do a snapshot of /// A snaphost of the state of the keyboard. [MethodImpl(MethodImplOptions.AggressiveInlining)] static KeyboardStateSnapshot GetStateSnapshot(IKeyboard keyboard) { if (_keyState is null) { _keyState = new bool[(int)Key.Count]; } for (Key key = 0; key < Key.Count; key++) { _keyState[(int)key] = keyboard.IsPressed(key); } return new KeyboardStateSnapshot(_keyState); } } }