aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/KeyboardDevice.cs
blob: 0e3630f264927866356fab1e78925aac13bbaf99 (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
30
31
32
33
34
35
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
using System;

namespace Ryujinx.HLE.HOS.Services.Hid
{
    public class KeyboardDevice : BaseDevice
    {
        public KeyboardDevice(Switch device, bool active) : base(device, active) { }

        public void Update(KeyboardInput keyState)
        {
            ref RingLifo<KeyboardState> lifo = ref _device.Hid.SharedMemory.Keyboard;

            if (!Active)
            {
                lifo.Clear();

                return;
            }

            ref KeyboardState previousEntry = ref lifo.GetCurrentEntryRef();

            KeyboardState newState = new()
            {
                SamplingNumber = previousEntry.SamplingNumber + 1,
            };

            keyState.Keys.AsSpan().CopyTo(newState.Keys.RawData.AsSpan());
            newState.Modifiers = (KeyboardModifier)keyState.Modifier;

            lifo.Write(ref newState);
        }
    }
}