Created
August 5, 2011 01:28
-
-
Save rwaldron/1126744 to your computer and use it in GitHub Desktop.
Special builds of Firefox 8 are shipping with joystick events
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
<script src="joystick.js"></script> |
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
/* | |
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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay! Just added joystick controls to my Miner! clone: http://valentinlaube.de/projects/miner/