aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Input/KeyboardStateSnapshot.cs
blob: abf85666bac4611787015370507dcdb47d66df17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Runtime.CompilerServices;

namespace Ryujinx.Input
{
    /// <summary>
    /// A snapshot of a <see cref="IKeyboard"/>.
    /// </summary>
    public class KeyboardStateSnapshot
    {
        private readonly bool[] _keysState;

        /// <summary>
        /// Create a new <see cref="KeyboardStateSnapshot"/>.
        /// </summary>
        /// <param name="keysState">The keys state</param>
        public KeyboardStateSnapshot(bool[] keysState)
        {
            _keysState = keysState;
        }

        /// <summary>
        /// Check if a given key is pressed.
        /// </summary>
        /// <param name="key">The key</param>
        /// <returns>True if the given key is pressed</returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsPressed(Key key) => _keysState[(int)key];
    }
}