• Stars
    star
    101
  • Rank 336,917 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎮 Simple customizable event binding for the HTML Gamepad API.

gamepad.js

🎮 Simple customizable event binding for the HTML Gamepad API.

Setup

$ npm install neogeek/gamepad.js
const gamepad = new Gamepad();

gamepad.start();

Usage

Pressed

const gamepad = new Gamepad();

gamepad.on('pressed', 'button_1', ({ id, gamepadIndex, value }) => {
    console.log(
        `${id} was pressed by player ${
            gamepadIndex + 1
        } with a value of ${value}!`
    );
});

gamepad.start();

Held

const gamepad = new Gamepad();

gamepad.on('held', 'button_1', ({ id, gamepadIndex, value }) => {
    console.log(
        `${id} is being held by player ${
            gamepadIndex + 1
        } with a value of ${value}!`
    );
});

gamepad.start();

Released

const gamepad = new Gamepad();

gamepad.on('released', 'button_1', ({ id, gamepadIndex, value }) => {
    console.log(
        `${id} was released by player ${
            gamepadIndex + 1
        } with a value of ${value}!`
    );
});

gamepad.start();

Axes

const gamepad = new Gamepad();

gamepad.on('axes', 0, ({ id, gamepadIndex, value }) => {
    console.log(
        `${id} was held by player ${gamepadIndex + 1} with a value of ${value}!`
    );
});

gamepad.on('axes', 1, ({ id, gamepadIndex, value }) => {
    console.log(
        `${id} was held by player ${gamepadIndex + 1} with a value of ${value}!`
    );
});

gamepad.start();

Removing Event Listeners

gamepad.off('pressed', 'button_1');

gamepad.off('held', 'button_1');

gamepad.off('released', 'button_1');

Migrating from v0.x to v1

  1. All keypad support has been removed to reduce complexity in the package.
  2. Gamepad type press is now pressed to conform to the browser standard.
  3. Gamepad type hold is now held.
  4. Gamepad type release is now released.

Support

The Gamepad browser API is very fragmented. VERY. Because of this we need your help. If you have a gamepad that isn't listed below, please visit the Gamepad.js Recorder and follow the instructions to create a controller mapping file. Either submit that in an issue or a PR. Once the mapping has been confirmed by at least one other user, it can be merged into the repo and it will be avaible in the next deploy.

Controller Browser OS Supported
PS4 Wired Chrome macOS
PS4 Wired Chrome Windows
PS4 Wired Firefox macOS
PS4 Wired Firefox Windows
PS4 Wired Microsoft Edge Windows
PS4 Wired Opera macOS
PS4 Wired Opera Windows
PS4 Wired Safari macOS
Switch Pro Wired Chrome macOS
Switch Pro Wired Chrome Windows
Switch Pro Wired Firefox macOS
Switch Pro Wired Firefox Windows
Switch Pro Wired Opera macOS
Switch Pro Wired Opera Windows
Switch Pro Wired Safari macOS
Xbox One Wired Chrome macOS
Xbox One Wired Chrome Windows
Xbox One Wired Firefox macOS
Xbox One Wired Firefox Windows
Xbox One Wired Microsoft Edge Windows
Xbox One Wired Opera macOS
Xbox One Wired Opera Windows
Xbox One Wired Safari macOS

More Repositories

1

get-unity

🕹 Command line tool for getting the download URL for the latest or specific version of Unity.
JavaScript
48
star
2

nodejs-starter-kit

🚀 This repo is a starter kit for working with Node.js, Handlebars, Sass, and Babel.
JavaScript
24
star
3

Unity-Snippets

A collection of code snippets I found useful while coding in Unity.
23
star
4

unity-package-example

C#
22
star
5

websocket-game-lobby

🔧 Simple API for building games using WebSockets.
TypeScript
17
star
6

unity-ci-tools

🔧 Bash scripts for running Unity tests on continuous integration services
Shell
14
star
7

pwa-starter-kit

🚀 Progressive Web Application Starter Kit
HTML
14
star
8

ios-device-svg-templates

📱 A growing collection of iOS devices built in SVG. Each template can be rendered with screenshots of appropriate sizes.
10
star
9

iOS-ObjC-Snippets

A collection of useful snippet for iOS development.
Objective-C
9
star
10

eslint-config-standards

🚦 ESLint Config Standards
JavaScript
8
star
11

spire-of-babel

🗼🐠 A one stop solution for working with ES6, React and TypeScript.
JavaScript
7
star
12

NETStandardClassLibraryTemplate

Template for building a .NET Standard Class Library in Rider.
C#
7
star
13

respond2png

A simple bash script for creating multiple screenshots of a responsive design.
Shell
6
star
14

cards-against-undefined

An undefined card game you play against friends, fiends and foes
JavaScript
5
star
15

mongoose-create-or-update

A Promise-based Mongoose plugin for creating and updating documents in a single statement.
JavaScript
5
star
16

lumberlogs

📝 A simple log aggregation tool.
JavaScript
5
star
17

Intro-to-NetCode-for-GameObjects

Intro to NetCode for GameObjects
ShaderLab
4
star
18

unity-ci-test-and-build-example

C#
4
star
19

dotfiles

@neogeek's dotfiles
Shell
4
star
20

jsdoc-regex

Regular expression for matching JSDoc comment blocks.
JavaScript
4
star
21

npmplease.com

HTML
3
star
22

websocket-unity

Simple wrapper for the websocket-csharp library.
C#
3
star
23

reactjs-starter-kit

⚛️ 🚀 This repo is a starter kit for working with React.js and ES6.
JavaScript
3
star
24

PokerSharp

PokerSharp is a small poker hand evaluation library.
C#
3
star
25

build-unity-android-plugin

🔧 Build Android plugins for Unity without needing to setup an Android project.
Shell
3
star
26

notion-to-json

Fetch Notion Pages as JSON
TypeScript
2
star
27

UnityAndroidPluginTemplate

Java
2
star
28

gta3-intro

An experiment using CSS3 animations.
HTML
2
star
29

.vscode

My custom ~/.vscode setup.
2
star
30

mailmake

✉️ Generate RFC1521 valid mime files for use with Mailgun and other similar services.
JavaScript
2
star
31

bash-snippets

A collection of code snippets I found useful while coding in bash.
Shell
2
star
32

fetch

Wrapper around the browser method fetch that handles errors and response.
TypeScript
2
star
33

websocket-game-lobby-client-hooks

⚛️ React hooks for use with websocket-game-lobby
TypeScript
1
star
34

slowreveal

✏️ Animate SVG line drawings.
JavaScript
1
star
35

random-word-uuid

Return random words.
JavaScript
1
star
36

custom-webpack-cli

🎒 A no-frill webpack cli that requires next to nothing to get started.
JavaScript
1
star
37

advent-of-code-2022

Advent of Code 2022
TypeScript
1
star
38

unity-build-webgl

Build Unity project as WebGL
1
star
39

websocket-game-lobby-template

JavaScript
1
star
40

raspar

⛏ A simple to use Promise-based web scraper with local caching.
JavaScript
1
star
41

topdown

A simple, read-only, Trello board aggregator.
JavaScript
1
star
42

unity-check-updates

🔧 Command line tool for updating UPM packages.
JavaScript
1
star
43

parse-cmd-args

🔍 Returns an object containing the path and flags parsed from process.argv
TypeScript
1
star
44

talks

Slides and demos from various talks.
CSS
1
star
45

unity-http-get-with-body-request

C#
1
star
46

sketchpad

Sketchpad built with SVG
JavaScript
1
star
47

Unity-Travis-CI-Tests

C#
1
star
48

html5-game-demo

JavaScript
1
star
49

csharp_editorconfig

Custom .editorconfig for C#
1
star
50

homebrew-find-unity

Ruby
1
star
51

http-single-serve

⚙️ HTTP server for use with single page applications.
JavaScript
1
star
52

neogeek.tmbundle

A TextMate bundle containing a small collection of custom templates and commands.
1
star
53

sdl_cpp_game

C
1
star
54

create-app

▲ A heavily opinionated starter template.
TypeScript
1
star
55

Unity-Common-Assets

Makefile
1
star
56

onlybuild

A zero-config cli for building static websites.
TypeScript
1
star
57

rhythm-game-utilities

A collection of utilities for creating rhythm games.
C#
1
star
58

reader.js

Reader.js is a simple inbox-zero feed reader built to work on Heroku.
JavaScript
1
star