Options
All
  • Public
  • Public/Protected
  • All
Menu

Class InputState

State for input handling.

Hierarchy

  • InputState

Index

Constructors

  • Parameters

    • mapping: string = ""

      mapping name, can be "wasd", "zqsd", "ijkl", "hjkl" or ""

    Returns InputState

Properties

dir: Vec2 = ...
dirKeys: KeyType[][]
frameRequest: number
gamepadMappings: GamepadMapping[]
gamepadStates: Map<string, { down: boolean; justChecked: boolean }>[]
gamepads: Gamepad[]
keyState: Map<string, { down: boolean; justChecked: boolean }> = ...
mouse: Vec2
mouseButtonState: Map<MouseButton, { down: boolean; justChecked: boolean }> = ...
stoppers: (() => void)[]

Methods

  • anyKeyDown(keys: KeyType[]): boolean
  • Return true if any of the keys passed in the array parameter is down.

    Parameters

    Returns boolean

  • Return true if the button is held down.

    Parameters

    Returns boolean

  • check if a key has been pressed. Return true only once per press.

    Parameters

    Returns boolean

  • Return a vector in the direction of the movement according to the keyboard.

    Returns Vec2

  • gamepadButtonDown(gp: number, button: string): boolean
  • Check if a button is currently being held down.

    Parameters

    • gp: number
    • button: string

    Returns boolean

  • gamepadButtonPressed(gp: number, button: string): boolean
  • Check if a button have just been pressed.

    Parameters

    • gp: number
    • button: string

    Returns boolean

  • gamepadGetAxis(gp: number, axis: string): number
  • Return the value of the axis between -1 and 1.

    Parameters

    • gp: number
    • axis: string

    Returns number

  • gamepadIsMapped(gp: number): boolean
  • Return true if the gamepad is useable.

    Parameters

    • gp: number

    Returns boolean

  • gamepadNumber(): number
  • Return the number of connected gamepads

    Returns number

  • handleGamepadConnect(): void
  • Returns void

  • handleKeyDown(e: KeyboardEvent): void
  • Parameters

    • e: KeyboardEvent

    Returns void

  • handleKeyUp(e: KeyboardEvent): void
  • Parameters

    • e: KeyboardEvent

    Returns void

  • handleMouseDown(e: MouseEvent): void
  • Parameters

    • e: MouseEvent

    Returns void

  • handleMouseMov(e: MouseEvent): void
  • Parameters

    • e: MouseEvent

    Returns void

  • handleMouseUp(e: MouseEvent): void
  • Parameters

    • e: MouseEvent

    Returns void

  • return true as long as a key is held down

    Parameters

    Returns boolean

  • check if a key has been pressed. Return true only once per press.

    Parameters

    Returns boolean

  • loop(): void
  • Update hidden states.

    Returns void

  • Return the position of the mouse in pixels in the canvas.

    Parameters

    Returns Vec2

  • onKeyPress(callback: any): void
  • Setup an event handler for all

    Parameters

    • callback: any

    Returns void

  • Refresh the gamepad list

    Returns InputState

  • Change the mapping mode, can be "wasd", "zqsd", "ijkl", "hjkl" or ""

    Parameters

    • mapping: string

    Returns InputState

  • Start the monitoring of input events.

    Returns InputState

  • stop(): void
  • Stop the listeners for events.

    Returns void

  • updateGamepad(): void
  • Returns void

Generated using TypeDoc