carldanley / node-gamepad

node-gamepad is a package for node that allows you to effortlessly interface your node applications with a variety of gamepad controllers.
82 stars 32 forks source link

Allow a larger number of events to be bound #21

Closed andyfleming closed 7 years ago

andyfleming commented 8 years ago

Related to #20, this makes debugging easier

andyfleming commented 8 years ago

Example use case: Debugging input:

'use strict'

var GamePad = require( 'node-gamepad' );
var controller = new GamePad('logitech/gamepadf310', {debug: false});
controller.connect();

const buttons = [
  'back',
  'start',
  'dpadLeft',
  'dpadRight',
  'dpadUp',
  'dpadDown',
  'A',
  'B',
  'X',
  'Y',
  'LB',
  'RB',
  'LT',
  'RT'
]

// Bind a press and release event for each button to see if they are all working
buttons.forEach((btn) => {
  controller.on(btn + ':press', function() {
    console.log(btn + ':press')
  })
  controller.on(btn + ':release', function() {
    console.log(btn + ':release')
  })
})