html5-gamepad
Use gamepads consistently across HTML5 browsers
Last updated 3 years ago by ericlathrop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install html5-gamepad 
SYNC missed versions from official npm registry.

html5-gamepad

Use gamepads consistently across HTML5 browsers

Test gamepads and configure mappings here

example

var gamepads = require("html5-gamepad");

function render() {
	var gamepad = gamepads[0];

	var x = gamepad.axis("left stick x");
	if (x < 0) {
		// move left
	}
	if (x > 0) {
		// move right
	}

	if (gamepad.button("a")) {
		// jump
	}

	window.requestAnimationFrame(render);
}
window.requestAnimationFrame(render);

supported gamepads

If a controller is not listed below, it uses the mapping for the Xbox 360 gamepad on Chrome, which may or may not work. Additional mappings can be added to mappings/index.js.

  • Logitech Gamepad F310
  • Microsoft Xbox 360
  • Microsoft Xbox One
  • Sony PlayStation 4

axis(axis)

Returns the current position of axis for gamepad. Axes have a range between -1.0 and 1.0.

Available axis names are:

  • "left stick x"
  • "left stick y"
  • "right stick x"
  • "right stick y"
  • "dpad x"
  • "dpad y"
  • "left trigger"
  • "right trigger"

button(button)

Returns true if button is pressed on controller, and false otherwise.

Available buttons names are:

  • "a"
  • "b"
  • "x"
  • "y"
  • "left shoulder"
  • "right shoulder"
  • "back"
  • "start"
  • "home"
  • "left stick"
  • "right stick"
  • "left stick x"
  • "left stick y"
  • "right stick x"
  • "right stick y"
  • "dpad x"
  • "dpad y"
  • "left trigger"
  • "right trigger"

Install

With npm do:

npm install --save html5-gamepad

License

MIT

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

9 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)

Copyright 2014 - 2017 © taobao.org |