using System;
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Utilities;
namespace UnityEngine.InputSystem.LowLevel
{
///
/// Command to query the name of the current keyboard layout from a device.
///
[StructLayout(LayoutKind.Explicit, Size = InputDeviceCommand.kBaseCommandSize + kMaxNameLength)]
public unsafe struct QueryKeyboardLayoutCommand : IInputDeviceCommandInfo
{
public static FourCC Type { get { return new FourCC('K', 'B', 'L', 'T'); } }
internal const int kMaxNameLength = 256;
[FieldOffset(0)]
public InputDeviceCommand baseCommand;
[FieldOffset(InputDeviceCommand.kBaseCommandSize)]
public fixed byte nameBuffer[kMaxNameLength];
///
/// Read the current keyboard layout name from .
///
///
public string ReadLayoutName()
{
fixed(QueryKeyboardLayoutCommand * thisPtr = &this)
return StringHelpers.ReadStringFromBuffer(new IntPtr(thisPtr->nameBuffer), kMaxNameLength);
}
///
/// Write the given string to .
///
/// Keyboard layout name.
public void WriteLayoutName(string name)
{
fixed(QueryKeyboardLayoutCommand * thisPtr = &this)
StringHelpers.WriteStringToBuffer(name, new IntPtr(thisPtr->nameBuffer), kMaxNameLength);
}
public FourCC typeStatic => Type;
public static QueryKeyboardLayoutCommand Create()
{
return new QueryKeyboardLayoutCommand
{
baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + kMaxNameLength)
};
}
}
}