Created
May 18, 2021 01:15
-
-
Save apsillers/c390d1faae4e5cc133ed478c10fcc0bb to your computer and use it in GitHub Desktop.
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
// paste this into your console | |
// Warning: only do this after thoroughly comprehending it because pasting mystery code into your console is bad :p | |
var doEv=ev=>s=>document.dispatchEvent(new KeyboardEvent(ev,{bubbles:1,keyCode:s.toLowerCase().charCodeAt(0)-32})); | |
var press=doEv("keydown"); | |
var release=doEv("keyup"); | |
var readGamepad = function() { | |
if(navigator.getGamepads()[0].axes[1]>.5) { press("s"); } else { release("s"); } | |
if(navigator.getGamepads()[0].axes[1]<-.5) { press("w"); } else { release("w"); } | |
if(navigator.getGamepads()[0].axes[0]>.5) { press("d"); } else { release("d"); } | |
if(navigator.getGamepads()[0].axes[0]<-.5) { press("a"); } else { release("a"); } | |
requestAnimationFrame(readGamepad); | |
} | |
requestAnimationFrame(readGamepad); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment