var sound = document.createElement('audio'); sound.src = 'sound.mp3'; document.onkeydown = function(event) { if (event.keyCode == 112) sound.play(); };