Skip to main content

Keyboard

Provides keyboard support for Excalibur.

Index

Constructors

constructor

Properties

publicevents

events: EventEmitter<KeyEvents> = ...

Methods

publicclear

  • clear(): void
  • Returns void

publicemit

  • emit<TEventName>(eventName: TEventName, event: KeyEvents[TEventName]): void
  • emit(eventName: string, event?: any): void
  • Type parameters

    Parameters

    • eventName: TEventName
    • event: KeyEvents[TEventName]

    Returns void

publicgetKeys

  • Gets list of keys being pressed down


    Returns Keys[]

init

  • Initialize Keyboard event listeners


    Parameters

    Returns void

publicisHeld

  • isHeld(key: Keys): boolean
  • Tests if a certain key is held down. This is persisted between frames.


    Parameters

    • key: Keys

      Test whether a key is held down

    Returns boolean

publicoff

  • off<TEventName>(eventName: TEventName, handler: Handler<KeyEvents[TEventName]>): void
  • off(eventName: string, handler: Handler<unknown>): void
  • off(eventName: string): void
  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<KeyEvents[TEventName]>

    Returns void

publicon

  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<KeyEvents[TEventName]>

    Returns Subscription

publiconce

  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<KeyEvents[TEventName]>

    Returns Subscription

toggleEnabled

  • toggleEnabled(enabled: boolean): void
  • Parameters

    • enabled: boolean

    Returns void

publictriggerEvent

  • triggerEvent(type: down | up, key: Keys, character?: string): void
  • Trigger a manual key event


    Parameters

    • type: down | up
    • key: Keys
    • optionalcharacter: string

    Returns void

publicupdate

  • update(): void
  • Returns void

publicwasPressed

  • wasPressed(key: Keys): boolean
  • Tests if a certain key was just pressed this frame. This is cleared at the end of the update frame.


    Parameters

    • key: Keys

      Test whether a key was just pressed

    Returns boolean

publicwasReleased

  • wasReleased(key: Keys): boolean
  • Tests if a certain key was just released this frame. This is cleared at the end of the update frame.


    Parameters

    • key: Keys

      Test whether a key was just released

    Returns boolean