Skip to main content

Key Typed?

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 block

Description

The Key Typed? block returns 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. This 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

Inputs in this block:

  • Keyboard key from drop down
Key Typed block syntax

Example

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.

Key Typed example code

Notes

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.

  • Key Held? - Returns true continuously while a key is held down