@basementuniverse/input-manager
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Game Component: Input Manager

A component for handling input events and managing input device state.

How to use

Initialise the input manager before use:

import InputManager from '@basementuniverse/input-manager';

InputManager.initialise();

Update the input manager state:

class Game {
  // ...

  public update(context: CanvasRenderingContext2D) {
    InputManager.update();
  }
}

Check the state of input devices:

// Check if any key is currently down
InputManager.keyDown();

// Check if a specific key is currently down
InputManager.keyDown(code);

// Check if a key was pressed
InputManager.keyPressed(code?);

// Check if a key was released
InputManager.keyReleased(code?);

// Check if the main mouse button is currently down
InputManager.mouseDown();

// Check if the main mouse button was pressed
InputManager.mousePressed();

// Check if the main mouse button was released
InputManager.mouseReleased();

// Check if the mouse wheel was scrolled up
InputManager.mouseWheelUp();

// Check if the mouse wheel was scrolled down
InputManager.mouseWheelDown();

// Get the current mouse position in screen-space
const position = InputManager.mousePosition;

See here for a reference of key codes.

Options

const options = { ... };
InputManager.initialise(options);
Option Type Default Description
mouse boolean true Enable mouse input
mouseWheel boolean true Enable mouse wheel input
keyboard boolean true Enable keyboard input

Other components

Readme

Keywords

none

Package Sidebar

Install

npm i @basementuniverse/input-manager

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

92.8 kB

Total Files

5

Last publish

Collaborators

  • basementuniverse