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