npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

syncinput

v1.4.1

Published

<img src="./readme/logo.png" width=250/>

Downloads

18

Readme

GitHub versionnpm version

  • Synchronous keyboard, mouse and gamepad input for fixed step applications.
  • Multi-browser support, compatible with mobile devices and and touchscreen events.
  • Currently supports input from: Mouse, Keyboard, Gamepad, Touchscreen
  • Detailed API docs available on the docs folder of the project.
  • Demo of the library running from the examples directory.
  • TSDoc documentation available.

Sync Events

  • Browser events fire at a different rate than your application logic/render code.
  • This library allow to access input state for variable frame rate scenarios.
  • Skip the need to process out of sync browser callbacks.

Getting Started

  • Get from NPM using npm install syncinput --save-prod
  • Here is a small code example showing the basic functionality of the library.
import {Keyboard, Keys, Mouse, MouseButton, Touch, Gamepad, GamepadButton} from 'syncinput';

//Initialization
mouse = new Mouse();
keyboard = new Keyboard();
touch = new Touch();
gamepad = new Gamepad();

[...]

//Inside of the logic/rendering loop
mouse.update();
keyboard.update();

console.log("Position X:" mouse.position.x + " Y:" + mouse.position.y);
console.log("Delta X:" mouse.delta.x + " Y:" + mouse.delta.y);
console.log("Scroll wheel:" mouse.wheel);


if (touch.touchJustPressed(0)) 
{
	console.log("First touch point just pressed.");
}
if (touch.touchJustReleased(1)) 
{
	console.log("Second touch point just released.");
}

if(mouse.buttonPressed(MouseButton.LEFT))
{
	console.log("Mouse left is pressed");
}

if(mouse.buttonPressed(MouseButton.LEFT))
{
	console.log("Mouse left is pressed");
}

if(keyboard.keyPressed(Keys.W) || gamepad.buttonPressed(GamepadButton.UP))
{
	console.log("W is pressed or Gamepad UP is pressed");
}

if(keyboard.keyJustPressed(Keys.W))
{
	console.log("W was just pressed");
}
if(keyboard.keyJustReleased(Keys.W))
{
	console.log("W was just released");
}

Mouse

  • position {x, y} -Actual mouse position

  • delta {x, y} - Mouse delta since last time update() was called

  • wheel - Mouse wheel value

  • buttonPressed(button) - Check if mouse button is pressed (touchscreen tap same as left click)

  • buttonJustPressed(button) - Check if mouse button was just pressed

  • buttonJustReleased(button) - Check if mouse button was just released

  • setCanvas(canvas) - Attach canvas to mouse object for position coordinated to be calculated relatively to the canvas.

  • insideCanvas() - Check if mouse is inside attached canvas

  • setLock(value) - Set mouse lock on/off.

Keyboard

  • keyPressed(button) - Check if key is currently pressed
  • keyJustPressed(button) - Check if key was just pressed
  • keyJustReleased(button) - Check if key was just released
  • reset() - Reset all keys

Touch

  • points[] - List of touch points and their respective status.
  • pan(points) - Multi-touch pan, retuns the average position and movement delta.
  • pinchZoom() - Pinch to zoom (of the first two touch points) delta.
  • touchPressed(point) - Check if touch point is pressed
  • touchJustPressed(point) - Check if touch point was just pressed
  • touchJustReleased(point) - Check if touch point was just released

Gamepad

Gamepad input is only available in secure context using HTTPS.

  • buttonPressed(button) - Check if gamepad button is pressed
  • buttonJustPressed(button) - Check if gamepad button was just pressed
  • buttonJustReleased(button) - Check if gamepad button was just released
  • getAxis(index) - Get axial input value from its index from -1 to 1.
  • getAnalogueButton(index) - Get analog button from 0 to 1.
  • getGamepads() - Get list of available gamepads.
  • setGamepad(gamepad) - Set wich gamepad to use.