While Keyboard Pressing#
Input / Keyboard / While Keyboard Pressing
Description#
Executes every frame that the Keyboard key is being held down
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("While Keyboard Pressing")]
[Image(typeof(IconKey), ColorTheme.Type.Blue, typeof(BadgeDot))]
[Description("Executes every frame that the Keyboard key is being held down")]
[Category("Input/Keyboard/While Pressing")]
[Keywords("Button", "Hold", "Down")]
[Serializable]
public class TriggerCoreInputKeyboardHold : TriggerHandleSubscriptionBase<HandleOnInputKeyboard>
{
// EXPOSED MEMBERS: -----------------------------------------------------------------------
[SerializeField] private Key m_Key = Key.Space;
// PROPERTIES: ----------------------------------------------------------------------------
protected override string GetTitle(GameObject source)
{
string key = TextUtils.Humanize(this.m_Key);
return $"Pressing {TextUtils.ThemeAsKeyword(key)} Down";
}
// OVERRIDE METHODS: ----------------------------------------------------------------------
protected override void OnTrigger(GameObject target)
{
if (!Keyboard.current[this.m_Key].isPressed) return;
using Args args = Args.Get(this.Component, target);
this.Run(args);
}
}
}