Created
April 29, 2018 06:15
-
-
Save e-sung/ce67a6841dcc86a93faea8fc8bf90c00 to your computer and use it in GitHub Desktop.
Make Enter Key to Simulate Mouse click
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
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