Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@basementuniverse/input-manager

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@basementuniverse/input-manager

A component for handling input events and managing input device state

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-92.19%
Maintainers
0
Weekly downloads
 
Created
Source

Game Component: Input Manager

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

Installation

npm install @basementuniverse/input-manager

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(button?);

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

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

// 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);
OptionTypeDefaultDescription
elementWindow | HTMLElementwindowThe element to listen for mouse input events on
mousebooleantrueEnable mouse input
mouseWheelbooleantrueEnable mouse wheel input
keyboardbooleantrueEnable keyboard input
preventContextMenubooleanfalseTry to prevent the context menu from appearing on right-click

FAQs

Package last updated on 04 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc