Hello,I’m new to this forum.
so I’m trying to making a web app piano, how to view what key is being pressed in javascript ?
and I’m making this key on html5 canvas and want to show the information on the canvas too.
here’s my code for the keyboard
window.addEventListener(“keypress”,onKeyPress);
function onKeyPress(e)
{
console.log(e.keyCode);
var str = String.fromCharCode(e.keyCode);
console.log(str+”:”+e.keyCode);
var tune = new Audio();
if (e.keyCode == 113)
{
tune = new Audio(“Assets/Tune/C.mp3”);
tune.play();
}
else if ( e.keyCode == 119)
{
tune = new Audio(“Assets/Tune/D.mp3”);
tune.play();
}
else if ( e.keyCode == 101)
{
tune = new Audio(“Assets/Tune/E.mp3”);
tune.play();
}
}
Thanks.