evidently-input
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

Evidently Input

Build Status

A set of classes to make it easier and simpler to work with input (Mouse/Keyboard) in your games.

Getting Started

The full documentation can be found here.

Installing

Add it to your project via:

npm i --save evidently-input

Documentation

The simplest way to use this library is as follows:

  1. Create a new instance of MouseInput/KeyboardInput.
  2. Call registerListeners() passing document to it, to register the necessary listeners.
  3. At the end of every frame call update(), it must be done after you've done using the input methods.
  4. Where needed call the appropriate methods (eg. keyboardInput.isKeyDown()-).

An example code:

const mouseInput = new MouseInput();
const keyboardInput = new KeyboardInput();
 
// Registers necessary event listeners on the document
mouseInput.registerListeners(document);
keyboardInput.registerListeners(document);
 
setInterval(() => {
    console.log(mouseInput.localX, mouseInput.localY, keyboardInput.isKeyDown(' '));
    
    // This has to run every frame after you've done processing it, so ideally at the end.
    mouseInput.update();
    keyboardInput.update();
}, 1000/60);

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Links

Dependents (1)

Package Sidebar

Install

npm i evidently-input

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

36.9 kB

Total Files

12

Last publish

Collaborators

  • skell