Key typed?

From StarLogo Nova Wiki
Other languages:
key typed code block

True if the selected key is typed, meaning pressed and then released. Often used in an "if" block to set a condition for a one-time action that can be repeated by typing the key multiple times.


[▼] key typed? is a code block part of the keyboard drawer.

Usage

[▼] key typed? is a type of logic block that returns a boolean. A true is returned if a specific key denoted in the drop down is typed in the current tick.

Syntax

The Key Typed Block

Inputs in this block:

  1. keyboard key from drop down

Example

Key Typed example gif
Key Typed example code

In this version of the snake game, the direction the snake moves is determined by which key is typed. Since the snake is always moving forward, the player only needs to type an arrow key to change the snake’s direction.

Nuances

An important difference between [▼] key held? and [▼] key typed? is that [▼] key typed? returns true only on ticks when the specific key is held AND when it was not held on the previous tick.

Basically, [▼] key typed? returns true only on the tick when the button is first pushed and not on consecutive ticks. [▼] key held? returns true forever as long as the specific key is being held down.

We often use [▼] key typed? in an “if” block to set a condition for a one-time action that can be repeated by typing the key multiple times.

Related Blocks

Relevant Video Resources

Relevant Activities