Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 942
Tiff Nogueira Avatar asked Nov 16 '18 21:11

Tiff Nogueira


People also ask

How do I use F1 F12 key on MacBook Pro?

Show the function keysPress and hold the Fn (Function) key on your keyboard to see F1 through F12 in the Touch Bar. You can also make the function keys appear automatically when you use specific apps: Choose Apple menu  > System Preferences, then click Keyboard.

Why did Apple cancel the touch bar?

Despite the fan theories, Apple's vice president of worldwide marketing Greg Joswiak told Wired that customers just didn't like the touch feature. “There's no doubt that our Pro customers love that full-size, tactile feel of those function keys, and so that's the decision we made.

Why is the touch bar on my MacBook Pro not working?

FAQ about Mac Touch Bar not working You can effectively solve the MacBook Pro Touch Bar not working issue by resetting Touch Bar. To reset Touch Bar on MacBook Pro, you need to restart the Touch Bar and Control Strip by running these two commands in Terminal: 'sudo pkill TouchBarServer;' and 'sudo killall ControlStrip.

How do you get typing suggestions on Mac touch bar?

isn't shown in the Touch Bar, choose View > Customize Touch Bar, then select “Show typing suggestions.” Or choose Apple menu > System Preferences, click Keyboard , click Text, then select “Touch Bar typing suggestions.”


1 Answers

Using keydown instead of keypress works.

window.addEventListener('keydown', listenForKeypressEvent);
like image 65
Tiff Nogueira Avatar answered Sep 17 '22 19:09

Tiff Nogueira