aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Hid/HidDevices/KeyboardDevice.cs
blob: e8ed6a3e6a4e9be306bb6ffc6622d836c0d3f0fa (plain)
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
30
31
32
namespace Ryujinx.HLE.HOS.Services.Hid
{
    public class KeyboardDevice : BaseDevice
    {
        public KeyboardDevice(Switch device, bool active) : base(device, active) { }

        public unsafe void Update(KeyboardInput keyState)
        {
            ref ShMemKeyboard keyboard = ref _device.Hid.SharedMemory.Keyboard;

            int currentIndex = UpdateEntriesHeader(ref keyboard.Header, out int previousIndex);

            if (!Active)
            {
                return;
            }

            ref KeyboardState currentEntry = ref keyboard.Entries[currentIndex];
            KeyboardState previousEntry = keyboard.Entries[previousIndex];

            currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
            currentEntry.SampleTimestamp2 = previousEntry.SampleTimestamp2 + 1;

            for (int i = 0; i < 8; ++i)
            {
                currentEntry.Keys[i] = (uint)keyState.Keys[i];
            }

            currentEntry.Modifier = (ulong)keyState.Modifier;
        }
    }
}