Created
April 17, 2021 17:49
-
-
Save David256/7bd94438dc460ff14e93f6c77b3f76d4 to your computer and use it in GitHub Desktop.
I don't know why
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
const L = 37, R = 39, U = 38, D = 40; | |
let a = [ | |
[L, U, R, D], [L, D, R, U], | |
[R, U, L, D], [R, D, L, U], | |
[U, L, D, R], [U, R, D, L], | |
[D, L, U, R], [D, R, U, L] | |
]; | |
let d = document; | |
let c = d.getElementsByTagName("canvas")[0]; | |
let gdir = () => { return a[Math.floor(Math.random() * a.length)]; } | |
let sim = (co,t) => { | |
let eA = d.createEvent("HTMLEvents"); | |
let eB = d.createEvent("HTMLEvents"); | |
eA.initEvent("keydown", true, true); | |
eB.initEvent("keyup", true, true); | |
eA.keyCode = co; | |
eB.keyCode = co; | |
c.dispatchEvent(eA); | |
console.log(co, "down"); | |
setTimeout(() => { c.dispatchEvent(eB); console.log(co, "up") }, t); | |
}; | |
let floop = () => { | |
let dir = gdir(); | |
setTimeout(sim, 0, dir[0], 2000); | |
setTimeout(sim, 2000, dir[1], 2000); | |
setTimeout(sim, 4000, dir[2], 2000); | |
setTimeout(sim, 6000, dir[3], 2000); | |
setTimeout(floop, 8000); | |
}; | |
floop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment