No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QueryKeyNameCommand.cs 1.4KB

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