A game about forced loneliness, made by TACStudios
1using System;
2using System.Runtime.InteropServices;
3using UnityEngine.InputSystem.Utilities;
4
5namespace UnityEngine.InputSystem.LowLevel
6{
7 /// <summary>
8 /// Command to query the current name of a key according to the current keyboard layout.
9 /// </summary>
10 [StructLayout(LayoutKind.Explicit, Size = kSize)]
11 public unsafe struct QueryKeyNameCommand : IInputDeviceCommandInfo
12 {
13 public static FourCC Type => new FourCC('K', 'Y', 'C', 'F');
14
15 internal const int kMaxNameLength = 256;
16 internal const int kSize = InputDeviceCommand.kBaseCommandSize + kMaxNameLength + 4;
17
18 [FieldOffset(0)]
19 public InputDeviceCommand baseCommand;
20
21 [FieldOffset(InputDeviceCommand.kBaseCommandSize)]
22 public int scanOrKeyCode;
23
24 [FieldOffset(InputDeviceCommand.kBaseCommandSize + 4)]
25 public fixed byte nameBuffer[kMaxNameLength];
26
27 public string ReadKeyName()
28 {
29 fixed(QueryKeyNameCommand * thisPtr = &this)
30 {
31 return StringHelpers.ReadStringFromBuffer(new IntPtr(thisPtr->nameBuffer), kMaxNameLength);
32 }
33 }
34
35 public FourCC typeStatic => Type;
36
37 public static QueryKeyNameCommand Create(Key key)
38 {
39 return new QueryKeyNameCommand
40 {
41 baseCommand = new InputDeviceCommand(Type, kSize),
42 scanOrKeyCode = (int)key
43 };
44 }
45 }
46}