A game about forced loneliness, made by TACStudios
at master 1.9 kB view raw
1using System; 2using System.Runtime.InteropServices; 3using UnityEngine.InputSystem.Utilities; 4 5namespace UnityEngine.InputSystem.LowLevel 6{ 7 /// <summary> 8 /// Command to query the name of the current keyboard layout from a device. 9 /// </summary> 10 [StructLayout(LayoutKind.Explicit, Size = InputDeviceCommand.kBaseCommandSize + kMaxNameLength)] 11 public unsafe struct QueryKeyboardLayoutCommand : IInputDeviceCommandInfo 12 { 13 public static FourCC Type { get { return new FourCC('K', 'B', 'L', 'T'); } } 14 15 internal const int kMaxNameLength = 256; 16 17 [FieldOffset(0)] 18 public InputDeviceCommand baseCommand; 19 20 [FieldOffset(InputDeviceCommand.kBaseCommandSize)] 21 public fixed byte nameBuffer[kMaxNameLength]; 22 23 /// <summary> 24 /// Read the current keyboard layout name from <see cref="nameBuffer"/>. 25 /// </summary> 26 /// <returns></returns> 27 public string ReadLayoutName() 28 { 29 fixed(QueryKeyboardLayoutCommand * thisPtr = &this) 30 return StringHelpers.ReadStringFromBuffer(new IntPtr(thisPtr->nameBuffer), kMaxNameLength); 31 } 32 33 /// <summary> 34 /// Write the given string to <see cref="nameBuffer"/>. 35 /// </summary> 36 /// <param name="name">Keyboard layout name.</param> 37 public void WriteLayoutName(string name) 38 { 39 fixed(QueryKeyboardLayoutCommand * thisPtr = &this) 40 StringHelpers.WriteStringToBuffer(name, new IntPtr(thisPtr->nameBuffer), kMaxNameLength); 41 } 42 43 public FourCC typeStatic => Type; 44 45 public static QueryKeyboardLayoutCommand Create() 46 { 47 return new QueryKeyboardLayoutCommand 48 { 49 baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + kMaxNameLength) 50 }; 51 } 52 } 53}