Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Keyboard Keys#

Input / Keyboard Keys

  • Can Read

  • Cannot Write

Description#

Returns the value of four custom Keyboard keys as a Vector2

Parameters#

Name Description
Up The key that pushes the value towards the positive Y axis
Left The key that pushes the value towards the negative X axis
Down The key that pushes the value towards the negative Y axis
Right The key that pushes the value towards the positive X axis

Code#

using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Keyboard Keys")]
    [Category("Input/Keyboard Keys")]

    [Description("Returns the value of four custom Keyboard keys as a Vector2")]
    [Image(typeof(IconKey), ColorTheme.Type.Blue, typeof(BadgeArrowUp))]

    [Parameter("Up", "The key that pushes the value towards the positive Y axis")]
    [Parameter("Left", "The key that pushes the value towards the negative X axis")]
    [Parameter("Down", "The key that pushes the value towards the negative Y axis")]
    [Parameter("Right", "The key that pushes the value towards the positive X axis")]

    [Keywords("Move", "Keys", "Composite", "Custom", "Direction")]

    [Serializable]
    public class TypeVector2InputKeyboardKeys : TypeVector2
    {
        [SerializeField] private Key m_Up = Key.W;
        [SerializeField] private Key m_Left = Key.A;
        [SerializeField] private Key m_Down = Key.S;
        [SerializeField] private Key m_Right = Key.D;

        public override Vector2 Get(Args args)
        {
            Keyboard keyboard = Keyboard.current;
            if (keyboard == null) return default;

            Vector2 value = Vector2.zero;

            if (keyboard[this.m_Up].isPressed) value += Vector2.up;
            if (keyboard[this.m_Left].isPressed) value += Vector2.left;
            if (keyboard[this.m_Down].isPressed) value += Vector2.down;
            if (keyboard[this.m_Right].isPressed) value += Vector2.right;

            return value.normalized;
        }

        public override string ToString()
        {
            return $"Keys {this.m_Up} {this.m_Left} {this.m_Down} {this.m_Right}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.