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) { }
|
|
|
|
|
2021-10-25 00:13:20 +02:00
|
|
|
public void Update(KeyboardInput keyState)
|
2020-04-03 02:10:02 +02:00
|
|
|
{
|
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,
|
|
|
|
};
|
|
|
|
|
2022-08-11 23:07:37 +02:00
|
|
|
keyState.Keys.AsSpan().CopyTo(newState.Keys.RawData.AsSpan());
|
2021-05-02 22:01:30 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|