Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created August 4, 2011 21:19
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rwaldron/58b0f9ed647f72da9173 to your computer and use it in GitHub Desktop.
MozJoy* listeners
/*
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