2021-05-02 20:01:30 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
|
|
|
using System;
|
|
|
|
|
2020-04-03 00:10:02 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Hid
|
|
|
|
{
|
|
|
|
public class KeyboardDevice : BaseDevice
|
|
|
|
{
|
|
|
|
public KeyboardDevice(Switch device, bool active) : base(device, active) { }
|
|
|
|
|
2021-10-24 22:13:20 +00:00
|
|
|
public void Update(KeyboardInput keyState)
|
2020-04-03 00:10:02 +00:00
|
|
|
{
|
2021-05-02 20:01:30 +00:00
|
|
|
ref RingLifo<KeyboardState> lifo = ref _device.Hid.SharedMemory.Keyboard;
|
2020-04-03 00:10:02 +00:00
|
|
|
|
|
|
|
if (!Active)
|
|
|
|
{
|
2021-05-02 20:01:30 +00:00
|
|
|
lifo.Clear();
|
|
|
|
|
2020-04-03 00:10:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
ref KeyboardState previousEntry = ref lifo.GetCurrentEntryRef();
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
KeyboardState newState = new KeyboardState
|
2020-04-03 00:10:02 +00:00
|
|
|
{
|
2021-05-02 20:01:30 +00:00
|
|
|
SamplingNumber = previousEntry.SamplingNumber + 1,
|
|
|
|
};
|
|
|
|
|
2022-08-11 21:07:37 +00:00
|
|
|
keyState.Keys.AsSpan().CopyTo(newState.Keys.RawData.AsSpan());
|
2021-05-02 20:01:30 +00:00
|
|
|
newState.Modifiers = (KeyboardModifier)keyState.Modifier;
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
lifo.Write(ref newState);
|
2020-04-03 00:10:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|