hid: Initial Keyboard Support (#684)
* hid: Initial Keyboard Support This adds basic hid keyboard support. Because of OpenTK.Input limitations, some specials keys aren't mapped. * Fix code style * Fix for loops code style * Make hid keyboard feature toggleable * Address comments * Fix 2 other nits * Apply jd's suggestion
This commit is contained in:
parent
3079c6a659
commit
12badfffb9
8 changed files with 261 additions and 1 deletions
|
@ -39,6 +39,11 @@ namespace Ryujinx.HLE.Input
|
|||
PrimaryController.Connect(controllerId);
|
||||
}
|
||||
|
||||
public void InitilizeKeyboard()
|
||||
{
|
||||
_device.Memory.FillWithZeros(HidPosition + HidKeyboardOffset, HidKeyboardSize);
|
||||
}
|
||||
|
||||
public HidControllerButtons UpdateStickButtons(
|
||||
HidJoystickPosition leftStick,
|
||||
HidJoystickPosition rightStick)
|
||||
|
@ -132,6 +137,33 @@ namespace Ryujinx.HLE.Input
|
|||
}
|
||||
}
|
||||
|
||||
public void WriteKeyboard(HidKeyboard keyboard)
|
||||
{
|
||||
long keyboardOffset = HidPosition + HidKeyboardOffset;
|
||||
long lastEntry = _device.Memory.ReadInt64(keyboardOffset + 0x10);
|
||||
long currEntry = (lastEntry + 1) % HidEntryCount;
|
||||
long timestamp = GetTimestamp();
|
||||
|
||||
_device.Memory.WriteInt64(keyboardOffset + 0x00, timestamp);
|
||||
_device.Memory.WriteInt64(keyboardOffset + 0x08, HidEntryCount);
|
||||
_device.Memory.WriteInt64(keyboardOffset + 0x10, currEntry);
|
||||
_device.Memory.WriteInt64(keyboardOffset + 0x18, HidEntryCount - 1);
|
||||
|
||||
long keyboardEntryOffset = keyboardOffset + HidKeyboardHeaderSize;
|
||||
long lastEntryOffset = keyboardEntryOffset + lastEntry * HidKeyboardEntrySize;
|
||||
long sampleCounter = _device.Memory.ReadInt64(lastEntryOffset);
|
||||
|
||||
keyboardEntryOffset += currEntry * HidKeyboardEntrySize;
|
||||
_device.Memory.WriteInt64(keyboardEntryOffset + 0x00, sampleCounter + 1);
|
||||
_device.Memory.WriteInt64(keyboardEntryOffset + 0x08, sampleCounter);
|
||||
_device.Memory.WriteInt64(keyboardEntryOffset + 0x10, keyboard.Modifier);
|
||||
|
||||
for (int i = 0; i < keyboard.Keys.Length; i++)
|
||||
{
|
||||
_device.Memory.WriteInt32(keyboardEntryOffset + 0x18 + (i * 4), keyboard.Keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
internal static long GetTimestamp()
|
||||
{
|
||||
return PerformanceCounter.ElapsedMilliseconds * 19200;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue