2021-05-02 22:01:30 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
|
|
|
using System;
|
|
|
|
|
2020-04-03 02:10:02 +02:00
|
|
|
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)
|
|
|
|
{
|
2021-05-02 22:01:30 +02:00
|
|
|
ref RingLifo<KeyboardState> lifo = ref _device.Hid.SharedMemory.Keyboard;
|
2020-04-03 02:10:02 +02:00
|
|
|
|
|
|
|
if (!Active)
|
|
|
|
{
|
2021-05-02 22:01:30 +02:00
|
|
|
lifo.Clear();
|
|
|
|
|
2020-04-03 02:10:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-02 22:01:30 +02:00
|
|
|
ref KeyboardState previousEntry = ref lifo.GetCurrentEntryRef();
|
2020-04-03 02:10:02 +02:00
|
|
|
|
2021-05-02 22:01:30 +02:00
|
|
|
KeyboardState newState = new KeyboardState
|
2020-04-03 02:10:02 +02:00
|
|
|
{
|
2021-05-02 22:01:30 +02:00
|
|
|
SamplingNumber = previousEntry.SamplingNumber + 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
keyState.Keys.AsSpan().CopyTo(newState.Keys.RawData.ToSpan());
|
|
|
|
newState.Modifiers = (KeyboardModifier)keyState.Modifier;
|
2020-04-03 02:10:02 +02:00
|
|
|
|
2021-05-02 22:01:30 +02:00
|
|
|
lifo.Write(ref newState);
|
2020-04-03 02:10:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|