vendredi 19 juin 2020

Why isn't this last event code if statement triggering?

I want to trigger code with different key presses:

document.addEventListener("keydown", event => {
    ;(async () => {
        if (event.key === 'b' && event.ctrlKey) {
            alert('1')
        } else if (event.code === 'Space' && event.ctrlKey) {
            alert('2')
        } else if (event.code === 'q' && event.ctrlKey) {
            alert('3')
        }
    })()
})

The strange thing is that the last if statement won't trigger. Even if I swap b for q.

What could be the reason?

There are no errors whatsoever.

https://jsfiddle.net/wn78dc5r/

Aucun commentaire:

Enregistrer un commentaire