Hierarchy

Constructors

  • Simple inputs manager to abstract key/mouse inputs.

    Parameters

    Returns GameInputs

Properties

_bindPressCount: any
_keyBindmap: any
_keyStates: any
_pressedDuringMeta: any

For a macOs bug workaround

_touches: any
allowContextMenu: boolean

When this is false, the context menu will be prevented from opening if there is a binding to the right mouse button.

disabled: boolean

When disabled, no binding events will fire.

down: any

Event emitter for binding press events. The original mouse or key event will be passed as an argument.

element: Document | HTMLElement

The HTMLElement that inputs is bound to.

filterEvents: ((ev, bindingName) => boolean)

Type declaration

    • (ev, bindingName): boolean
    • Optional filter function. Useful if you want to, e.g., ignore a key binding if ctrl/alt are pressed, but allow that same binding if it originated from a mouse event.

      Parameters

      • ev: KeyboardEvent & MouseEvent
      • bindingName: string

      Returns boolean

pointerState: {
    dx: number;
    dy: number;
    scrollx: number;
    scrolly: number;
    scrollz: number;
}

Numeric counters representing accumulated pointer/scroll inputs since the last time tick was called.

Type declaration

  • dx: number
  • dy: number
  • scrollx: number
  • scrolly: number
  • scrollz: number
pressCount: {
    [key: string]: number;
}

How many times each binding has been pressed since the last time tick was called.

Type declaration

  • [key: string]: number
preventDefaults: boolean

When true, all key events with bindings will call preventDefaults.

releaseCount: {
    [key: string]: number;
}

How many times each binding has been released since the last time tick was called.

Type declaration

  • [key: string]: number
state: {
    [key: string]: boolean;
}

The boolean state of whether each binding is currently pressed.

inputs.state['move-left'] // true if a bound key is pressed

Type declaration

  • [key: string]: boolean
stopPropagation: boolean

When true, all key events with bindings will call stopPropagation.

up: any

Event emitter for binding release events. The original mouse or key event will be passed as an argument.

version: string

Methods

  • Binds one or more physical keys to an arbitrary binding name. Key strings should align to KeyboardEvent.code strings - e.g. KeyA, ArrowDown, etc.

    `inputs.bind('move-player-left', 'KeyW', 'ArrowLeft')

    Parameters

    • bindingName: string
    • Rest ...keys: string[]

    Returns void

  • Returns a copy of all existing bindings, in the format:

      {
    bindingName: [ keyCode1, keyCode2, ... ]
    ...
    }

    Returns {}

    • Tick function - clears out all cumulative counters

      Returns void

    • Removes all key bindings for a given binding name.

      `inputs.unbind('move-player-left')

      Parameters

      • bindingName: any

      Returns void

    Generated using TypeDoc