using System.Buffers; using System.Runtime.CompilerServices; using ConfigPhysicalKey = Ryujinx.Common.Configuration.Hid.PhysicalKey; 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)ConfigPhysicalKey.Count]; } for (ConfigPhysicalKey key = 0; key < ConfigPhysicalKey.Count; key++) { _keyState[(int)key] = keyboard.IsPressed((Key)(int)key); } return new KeyboardStateSnapshot(_keyState); } /// /// Try to consume a recently pressed key. /// /// The pressed key, if available. /// True if a key press was consumed. bool TryConsumePressedKey(out Key key) { key = Key.Unknown; return false; } } }