I want to be able to play a mp3 file when the tab key is pressed on a keyboard.
I am making a number system for a restaurant and when a number is entered and tab is pressed, it will make a noise which will draw attention to the numbers.
Thanks!
My current code is this. It doesn't work... Please correct me!
<script>
window.addEventListener("keydown", checkKeyPressed, false);
function checkKeyPressed(e) {
if (e.keyCode == "9") {
//Play Music
document.getElementById('aud').play()
}
}
</script>
<audio src="music.mp3" id="aud">
<p>Your browser does not support the audio element.</p>
</audio>
I also made it hidden in css and the music file is in the same folder... It is not working...