Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
489 B
2
Indexable
Never

const piano_letters = ["KeyA","KeyS","KeyD","KeyF","KeyG","KeyH","KeyJ"] // for event.code
// const piano_letters = ["A","S","D","F","G","H","J"] // for event.key

document.addEventListener("keydown", function(event){
    const letter = event.code.toUppercase();  // event.key
    const pianoKey = 'Key'+letter;
    
    if (piano_letters.includes(pianoKey)) {
        console.log(`The '${letter}' key is pressed.`);
    } else {
        console.log(`${letter} key is unbound`);
    }
});