Skip to the content.

GitHub versionnpm version

Sync Events

Getting Started

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

Keyboard

Touch

Gamepad

Gamepad input is only available in secure context using HTTPS.