Keyboard Key Name#
Input / Keyboard Key Name
Can Read
Cannot Write
Description#
The name the specified key has on the current Keyboard layout
Parameters#
| Name | Description |
|---|---|
| Key | The Keyboard key that is read |
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Inline(nameof(m_Key))]
[Title("Keyboard Key Name")]
[Category("Input/Keyboard Key Name")]
[Description("The name the specified key has on the current Keyboard layout")]
[Image(typeof(IconKey), ColorTheme.Type.Blue)]
[Parameter("Key", "The Keyboard key that is read")]
[Keywords("Display", "Label", "Prompt", "Layout", "AZERTY", "QWERTY")]
[Serializable]
public class TypeStringInputKeyboardKeyName : TypeString
{
[SerializeField] private Key m_Key = Key.Space;
public override string Get(Args args)
{
Keyboard keyboard = Keyboard.current;
return keyboard != null ? keyboard[this.m_Key].displayName : string.Empty;
}
public override string ToString()
{
return $"Key {this.m_Key} Name";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}