Singularity/Library/PackageCache/com.unity.visualscripting@1.../Documentation~/vs-nodes-events-on-keyboard...
2024-05-06 11:45:45 -07:00

3.7 KiB

On Keyboard Input node

Note

The On Keyboard Input [!includenodes-note-manual]

The On Keyboard Input node listens for a specified action on a keyboard key. [!includenodes-desc-end]

An image of the Graph window. An On Keyboard Input node displays with its details in the Graph Inspector.

Fuzzy finder category

The On Keyboard Input node is in the Events > Input category in the fuzzy finder.

Inputs

The On Keyboard Input [!includenodes-inputs]

Name Type Description
Key Key Code The name of the keyboard key the node listens to for an Input event. For a list of all available keys, see the KeyCode page's Properties section in the Unity User manual.
Action Press State The specific press state of the key that the node listens for.
Hold The user holds down the key.
Down The user presses the key.
Up The user releases the key.

Additional node settings

The On Keyboard Input [!includenodes-additional-settings]

[!include[nodes-coroutine](./snippets/nodes-coroutine.md)]
Name Type Description

Outputs

The On Keyboard Input [!includenodes-single-output]

[!include[nodes-input-output-trigger](./snippets/input-manager/nodes-input-output-trigger.md)]
Name Type Description

Example graph usage

In the following example, the On Keyboard Input node listens for when the user presses the Space key. When the user presses Space, the On Keyboard Input triggers the Transform Translate node and lifts the GameObject along its Y coordinate by 5 units. This makes the GameObject jump.

An image of the Graph window. An On Keyboard Input node uses inline values to assign its Key as Space and its Action as Down. Its Trigger output port connects to the Invoke input port on a Transform Translate node. The Translate node uses an inline value of This for its Target, and an inline value of 5 for its Y input.

An image of the Game view. A cylinder and square sit on a plane, with a sphere lifted into the air between them.

[!includenodes-related] the On Keyboard Input node: