MozJoy* listeners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This gist predates the current GamepadAPI, preserved it for posterity. | |
https://wiki.mozilla.org/GamepadAPI | |
MozJoyAxisMove | |
MozJoyButtonUp | |
MozJoyButtonDown | |
*/ | |
var joyEvents = { | |
MozJoyAxisMove: { | |
props: [ "joystickID", "axis", "value" ], | |
listen: 1 | |
}, | |
MozJoyButtonUp: { | |
props: [ "joystickID", "button" ], | |
listen: 1 | |
}, | |
MozJoyButtonDown: { | |
props: [ "joystickID", "button" ], | |
listen: 1 | |
} | |
}; | |
// For each type of joystick event, add an event listener to log events | |
Object.keys( joyEvents ).forEach(function( type, idx ) { | |
var joyEvent = joyEvents[ type ]; | |
if ( joyEvent.listen ) { | |
window.addEventListener( type, function( event ) { | |
console.log( | |
type, | |
joyEvent.props.map(function( val ) { | |
return val + ": " + event[ val ]; | |
}).join(", ") | |
); | |
}, false); | |
} | |
if ( idx === Object.keys( joyEvents ).length - 1 ) { | |
console.log( "MozJoy* Events Ready" ); | |
} | |
}, joyEvents ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment