Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created September 23, 2020 10:03
Show Gist options
  • Save ntakouris/9de35f735e9ffb616abb424a700c260e to your computer and use it in GitHub Desktop.
Save ntakouris/9de35f735e9ffb616abb424a700c260e to your computer and use it in GitHub Desktop.
async function toggleAction(action) {
setActionText(action)
switch(action) {
case 'jump':
console.log('jump')
var e = new KeyboardEvent('keydown',{'keyCode':32, 'which':32});
document.dispatchEvent(e);
break;
case 'crouch':
var e = new KeyboardEvent('keydown',{'keyCode':40, 'which':40});
document.dispatchEvent(e);
break;
case 'idle':
var e = new KeyboardEvent('keyup',{'keyCode': 40, 'which':40});
document.dispatchEvent(e);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment