Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created August 5, 2011 01:28
Show Gist options
  • Save rwaldron/1126744 to your computer and use it in GitHub Desktop.
Save rwaldron/1126744 to your computer and use it in GitHub Desktop.
Special builds of Firefox 8 are shipping with joystick events
<script src="joystick.js"></script>
/*
MozJoyAxisMove
MozJoyButtonUp
MozJoyButtonDown
*/
var joyEvents = {
MozJoyAxisMove: {
props: [ "joystickID", "axis", "value" ],
listen: 1
},
MozJoyButtonUp: {
props: [ "joystickID", "button" ],
listen: 1
},
MozJoyButtonDown: {
props: [ "joystickID", "button" ],
listen: 1
}
},
joyEventsKeys = Object.keys( joyEvents );
// Iterate joystick events, add an event listener to the window to log events
joyEventsKeys.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 === joyEventsKeys.length - 1 ) {
console.log( "MozJoy* Events Ready" );
}
}, joyEvents );
@rwaldron
Copy link
Author

rwaldron commented Aug 5, 2011

@vlenhart
Copy link

vlenhart commented Aug 9, 2011

Yay! Just added joystick controls to my Miner! clone: http://valentinlaube.de/projects/miner/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment