Skip to content

@rwaldron /joystick.js secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.