IKeyboard.cs
1 using System.Runtime.CompilerServices; 2 3 namespace Ryujinx.Input 4 { 5 /// <summary> 6 /// Represent an emulated keyboard. 7 /// </summary> 8 public interface IKeyboard : IGamepad 9 { 10 /// <summary> 11 /// Check if a given key is pressed on the keyboard. 12 /// </summary> 13 /// <param name="key">The key</param> 14 /// <returns>True if the given key is pressed on the keyboard</returns> 15 bool IsPressed(Key key); 16 17 /// <summary> 18 /// Get a snaphost of the state of the keyboard. 19 /// </summary> 20 /// <returns>A snaphost of the state of the keyboard.</returns> 21 KeyboardStateSnapshot GetKeyboardStateSnapshot(); 22 23 /// <summary> 24 /// Get a snaphost of the state of a keyboard. 25 /// </summary> 26 /// <param name="keyboard">The keyboard to do a snapshot of</param> 27 /// <returns>A snaphost of the state of the keyboard.</returns> 28 [MethodImpl(MethodImplOptions.AggressiveInlining)] 29 static KeyboardStateSnapshot GetStateSnapshot(IKeyboard keyboard) 30 { 31 bool[] keysState = new bool[(int)Key.Count]; 32 33 for (Key key = 0; key < Key.Count; key++) 34 { 35 keysState[(int)key] = keyboard.IsPressed(key); 36 } 37 38 return new KeyboardStateSnapshot(keysState); 39 } 40 } 41 }