Skip to content

Instantly share code, notes, and snippets.

@sielicki
Created December 5, 2017 00:12
Show Gist options
  • Save sielicki/a145aced91799020a08778e8f363319a to your computer and use it in GitHub Desktop.
Save sielicki/a145aced91799020a08778e8f363319a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name gamepadify
// @version 0.1
// @include http://*.koalabeast.com:*
// @include http://*.jukejuice.com:*
// @include http://*.newcompte.*
// @author sielicki
// ==/UserScript==
var s = [false,false,false,false];
function delta(gp){
a = Math.round(gp.axes[0]*10); b = Math.round(gp.axes[1]*10);
if ((s[0] != (s[0] = a>=0))) tagpro.sendKeyPress("left", s[0]);
if ((s[1] != (s[1] = a<=0))) tagpro.sendKeyPress("right", s[1]);
if ((s[2] != (s[2] = b>=0))) tagpro.sendKeyPress("up", s[2]);
if ((s[3] != (s[3] = b<=0))) tagpro.sendKeyPress("down", s[3]);
}
tagpro.ready(function() {
window.addEventListener("gamepadconnected", function(e) {
setInterval(function(){
if (navigator.getGamepads) delta(navigator.getGamepads()[0]);
}, 50);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment