简体   繁体   English

Apple Touch Bar键不触发按键事件

[英]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? 当我想收听Apple Touch Bar按键时是否还有其他事件可以收听? Specifically, I would like to listen for the Escape keypress event. 具体来说,我想听听Escape keypress事件。

My code is working on "regular" keyboards, with actual escape keys, but not with the Touch Bar. 我的代码使用的是“常规”键盘,带有实际的转义键,但没有使用Touch Bar。

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

window.addEventListener('keypress', listenForKeypressEvent);

使用keydown代替keypress可以工作。

window.addEventListener('keydown', listenForKeypressEvent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM