Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KeyboardContext

KeyboardContext represents a single 'mode' of the game's keyboard controls. For instance, you might have one context to use for the overworld, another for menus, another for inventory, etc.

You can set the active context through a KeyboardHandler's setContext(ctx) and clearContext() methods.

Normally the onDown/onUp callbacks can be used to listen for specific keys, but for more control onAnyDown/onAnyUp can be used to register callbacks that fire on any key press. These 'any' callbacks will always be the first to be called during a new key press.

You can register multiple 'any' callbacks or key-specific callbacks for rare patterns,for instance registering 2 callbacks to fire when the 'E' key is pressed, etc.

Hierarchy

  • KeyboardContext

Index

Methods

callOnDown

callOnUp

clearOnAnyDown

  • Clear a callback listening for any key. If no callback is provided, will clear all callbacks on listening for any keys.

    Parameters

    Returns void

clearOnAnyUp

  • Clear a callback listening for any key. If no callback is provided, will clear all callbacks on listening for any keys.

    Parameters

    Returns void

clearOnDown

  • Clear an existing callback for a key. If no callback is provided, will clear all callbacks on that key.

    Parameters

    • key: KeyCode | number

      KeyCode - The keycode to clear onDown.

    • Optional callback: KeyboardContextCallback

      If no existing event is provided, will clear all

    Returns void

clearOnUp

  • Clear an existing callback for a key. If no callback is provided, will clear all callbacks on that key.

    Parameters

    • key: KeyCode | number

      KeyCode - The keycode to clear onUp.

    • Optional callback: KeyboardContextCallback

      If no existing event is provided, will clear all

    Returns void

onAnyDown

onAnyUp

onDown

onUp

Generated using TypeDoc