Skip to content

Instantly share code, notes, and snippets.

@e-sung
Created April 29, 2018 06:15
Show Gist options
  • Save e-sung/ce67a6841dcc86a93faea8fc8bf90c00 to your computer and use it in GitHub Desktop.
Save e-sung/ce67a6841dcc86a93faea8fc8bf90c00 to your computer and use it in GitHub Desktop.
Make Enter Key to Simulate Mouse click
var cursorX = 0
var cursorY = 0
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;
}
document.addEventListener('keypress', function (e) {
var key = e.which || e.keyCode;
if (key === 13) { // 13 is enter
document.elementFromPoint(cursorX, cursorY).click();
playAudio();
}
});
function playAudio() {
var audio = new Audio('https://chewing-book.synology.me/wordpress/wp-content/uploads/2018/04/submitMusic.wav');
audio.type = 'audio/wav';
var playPromise = audio.play();
if (playPromise !== undefined) {
playPromise.then(function () {
console.log('Playing....');
}).catch(function (error) {
console.log('Failed to play....' + error);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment