Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Keyboard

A class that listens for keyboard events and tracks the current state of pressed keys.

Hierarchy

  • Keyboard

Index

Constructors

constructor

  • Returns Keyboard

Properties

Private pressed

pressed: Set<string | number> = new Set<string | number>()

Methods

addEventListeners

  • addEventListeners(): void
  • Add the appropriate keyboard event listeners.

    This method is called automatically when the keyboard is created.

    Returns void

Private handleEvent

  • handleEvent(event: KeyboardEvent): void
  • internal

    Parameters

    • event: KeyboardEvent

    Returns void

isDown

  • isDown(keyCodeOrName: number | string): boolean
  • Check whether a given key is down.

    let keys = new Keyboard();
    
    keyboard.isDown("enter");
    // or
    keyboard.isDown(Keyboard.KEY_ENTER);

    Parameters

    • keyCodeOrName: number | string

      The key code or name of a key

    Returns boolean

removeEventListeners

  • removeEventListeners(): void
  • Remove the event listeners for the keyboard. This can be used to stop the keyboard processing events.

    Returns void

Generated using TypeDoc