Skip to content

vdegenne/esm-gamecontroller.js

Repository files navigation

🎮 esm-gamecontroller.js

A esm port of gamecontroller.js.

All credit goes to:

However the original author doesn't seem to be active anymore, so I took JumpLink TS version and made a build step to convert it to ESM which is recommended if you want to include the source in your final build anyway.

On top of that I wrote some mappings so it's easier to find a button and use them in functions, e.g.

import {XBoxButton} from 'esm-gamecontroller.js';

gamepad.on(XBoxButton.START, () => {
	// ... pause the game or continue
})

Installation

npm add -D esm-gamecontroller.js

Usage

import gameControl, { GCGamepad } from 'esm-gamecontroller.js';

gameControl.on('connect', (gamepad: GCGamepad) => {
	// May the types lead you young padawan...
})