Beep8 logo

Input Documentation

Input Documentation Source Code

Input Methods

beep8.Input.getKeys(key)

Gets an array of keys that correspond to a given key. This is used to handle key aliases (e.g. “W” and “ArrowUp”).

Parameters

  • key (string): The key to get aliases for.

Returns

  • (string[]): An array of key names.

beep8.Input.init()

Initializes the input system.

beep8.Input.keyHeld(keyName)

Checks if a key is currently held down.

Parameters

  • keyName (string): The name of the key to check.

Returns

  • (boolean): Whether the key is currently held down.

beep8.Input.keyJustPressed(keyName)

Checks if a key was just pressed in the current frame.

Parameters

  • keyName (string): The name of the key to check.

Returns

  • (boolean): Whether the key was just pressed.

beep8.Input.onEndFrame()

Clears the list of keys that were just pressed. Should be called at the end of each frame.

beep8.Input.onKeyDown(e)

Handles keydown events, adding the key to the just pressed and held sets. Resolves any pending asynchronous key events.

Parameters

  • e (KeyboardEvent): The event object.

beep8.Input.onKeyUp(e)

Handles keyup events, removing the key from the held set.

Parameters

  • e (KeyboardEvent): The event object.

beep8.Input.onPointerDown(e)

Handles pointerdown events, resolving any pending asynchronous pointer events.

Parameters

  • e (PointerEvent): The event object.

beep8.Input.readKeyAsync()

Reads a key asynchronously. Returns a promise that resolves to the key that was pressed.

Returns

  • (*Promise*): A promise that resolves to the key that was pressed.

beep8.Input.readLine(initString, maxLen [,maxWidth]) async

Reads a line of text asynchronously. Handles user input to build a string until the Enter key is pressed.

Parameters

  • initString (string): The initial string to display.
  • maxLen (number): The maximum length of the string to read.
  • [maxWidth] (number): The maximum width of the line. (default: -1)

Returns

  • (*Promise*): A promise that resolves to the string that was read.

beep8.Input.readPointerAsync()

Reads a pointer asynchronously. Returns a promise that resolves to the pointer position.

Returns

  • (Promise<{x: number, y: number): >} A promise that resolves to the pointer position.

More Beep8 Docs

Actors Documentation

Async Documentation

Core Functions

Input Documentation

App Intro Documentation

Joystick Documentation

Menu Documentation

Music Documentation

Passcodes Documentation

Public API

Random Numbers Documentation

SFX Documentation

Tilemap Documentation

Utilities Documentation