KeyboardKeyAssigner.cs
1 namespace Ryujinx.Input.Assigner 2 { 3 /// <summary> 4 /// <see cref="IButtonAssigner"/> implementation for <see cref="IKeyboard"/>. 5 /// </summary> 6 public class KeyboardKeyAssigner : IButtonAssigner 7 { 8 private readonly IKeyboard _keyboard; 9 10 private KeyboardStateSnapshot _keyboardState; 11 12 public KeyboardKeyAssigner(IKeyboard keyboard) 13 { 14 _keyboard = keyboard; 15 } 16 17 public void Initialize() { } 18 19 public void ReadInput() 20 { 21 _keyboardState = _keyboard.GetKeyboardStateSnapshot(); 22 } 23 24 public bool IsAnyButtonPressed() 25 { 26 return GetPressedButton() is not null; 27 } 28 29 public bool ShouldCancel() 30 { 31 return _keyboardState.IsPressed(Key.Escape); 32 } 33 34 public Button? GetPressedButton() 35 { 36 Button? keyPressed = null; 37 38 for (Key key = Key.Unknown; key < Key.Count; key++) 39 { 40 if (_keyboardState.IsPressed(key)) 41 { 42 keyPressed = new(key); 43 break; 44 } 45 } 46 47 return !ShouldCancel() ? keyPressed : null; 48 } 49 } 50 }