Created
October 9, 2020 04:36
-
-
Save CallMeAreks/3bdec7c3006df08ce14125dca03dfb6b 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
(function(){ | |
var pressKey = async function(keyCode) { | |
document.dispatchEvent(new KeyboardEvent('keydown',{'key':keyCode})); | |
await new Promise(r => setTimeout(r, 50)); | |
document.dispatchEvent(new KeyboardEvent('keyup',{'key':keyCode})); | |
}; | |
var play = async function(sequence, delay = 200, spaceDelay = 200) { | |
const dict = { | |
" " : () => new Promise(r => setTimeout(r, spaceDelay)), | |
"m" : () => new Promise(r => pressKey(' ')), | |
}; | |
for await (const char of sequence) { | |
var action = dict[char] || pressKey; | |
await action(char); | |
await new Promise(r => setTimeout(r, delay)); | |
} | |
}; | |
window.player = { | |
play: play | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
await player.play("113165 113186 1107431 998 4 6 4 m", 300, 100);