I'm 3 weeks into learning JS, and am working on a project to build a playable piano. When typing the letter c, it will play the note c. That part is working fine, but now I want the user to hold the control key and type c to make it play a different note, c#. How would i set this up? Below is what I've tried working on, but I can't get this to work.
Any refactoring advice is also helpful - I'm going to have a lot more keys played
document.addEventListener('keydown', (playNote) =>{
if(playNote.key == 'c'){
document.getElementById('low-c').play();
}
if(playNote.key == 'c' && playNote.cntrlkey == true){
document.getElementById('low-c#').play();
}
}
Check this page for keyboard events.
You will find a value for if the ctrl key is pressed under
playNote.ctrlKeyThen do