Tiff Nogueira
Tiff Nogueira

Reputation: 141

Apple Touch Bar keys not firing keypress event

Is there another event I can listen for when I want to listen for an Apple Touch Bar keypress? Specifically, I would like to listen for the Escape keypress event.

My code is working on "regular" keyboards, with actual escape keys, but not with the Touch Bar.

listenForKeypressEvent = (e) => {
    console.log(e);
    if (e.keyCode === 27 || e.key === "Escape") {
        // do the things
    }
}

window.addEventListener('keypress', listenForKeypressEvent);

Upvotes: 6

Views: 2234

Answers (2)

Rajendran Nadar
Rajendran Nadar

Reputation: 5438

Not sure why but in my case keyup worked fine for me

window.addEventListener('keyup', listenForKeypressEvent);

Upvotes: 0

Tiff Nogueira
Tiff Nogueira

Reputation: 141

Using keydown instead of keypress works.

window.addEventListener('keydown', listenForKeypressEvent);

Upvotes: 8

Related Questions