Skip to content

Instantly share code, notes, and snippets.

@CallMeAreks
Created October 9, 2020 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CallMeAreks/3bdec7c3006df08ce14125dca03dfb6b to your computer and use it in GitHub Desktop.
Save CallMeAreks/3bdec7c3006df08ce14125dca03dfb6b to your computer and use it in GitHub Desktop.
(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
};
}());
@CallMeAreks
Copy link
Author

Usage:

await player.play("113165 113186 1107431 998 4 6 4 m", 300, 100);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment