Loading...

Logo
DocumentationBehaviorsInteractionKeyboard Event
Interaction

Keyboard Event

Last updated November 7, 2023

The Keyboard Event behavior listens for input from an external hardware keyboard and triggers other behaviors when a specified event occurs. This can be used to create keyboard controls for your game.

⚠️ Warning: This feature is only supported on iOS 13.0 and above.

PropertyDescription
Event

Select an event to listen to.

  • On Press - Trigger behaviors when a key has been pressed.
  • While Pressed - Trigger behaviors while a key is pressed.
  • On Release - Trigger behaviors when a key has been released.
  • On Sequence - Trigger behaviors when a sequence of keys have been pressed.
Key

Select any of the special keys on the keyboard to listen to: Up Arrow, Left Arrow, Right Arrow, Down Arrow, Spacebar, Shift, Delete, Control, Option, Caps Lock, Tab and Escape.

Or you can select Character and enter a single character on the keyboard to listen for like a or d.

Or you can select Any and listen to all keys on the keyboard.

Character SequenceEnter a sequence of characters (string) that must be pressed on the keyboard to trigger the behavior.
Output FieldDescription
key

The string representation of the key that was pressed. This will always be a single character, but for special keys like arrows, this will be blank.

("x", "a", "5", etc.)

keyCode

The numeric representation of the key that was pressed. Every key has a numeric value tied to it according to ASCII.

(78, 61, 35, etc.)

sequence

(On Sequence)

The character sequence.

sequenceLength

(On Sequence)

The length of the character sequence.

Example: Keyboard Controlled Player

The player moves left while the left arrow is held and the player moves right while the right arrow is held. When the user presses the up arrow, the player jumps.

EAB486CD-5710-4106-B089-2EC5DAC9BEA6.png

Example: An Easter Egg

When the user enters "party" on their keyboard, the screen shakes, confetti particles emit from the player and a celebratory sound effect is played.

89822D92-FC16-4C1E-B952-6539C223FA02.png