【发布时间】:2021-11-19 17:01:18
【问题描述】:
我正在尝试在我的 electron.js 应用中禁用所有键盘快捷键。
我尝试了以下方法(剧透警告:它们不起作用):
globalShortcut.unregisterAll()
和
globalShortcut.register('Alt+CommandOrControl+A', () => {
console.log('not allowed')
})
globalShortcut.register('Alt+CommandOrControl+B', () => {
console.log('not allowed')
})
globalShortcut.register('Alt+CommandOrControl+C', () => {
console.log('not allowed')
})
globalShortcut.register('Alt+CommandOrControl+D', () => {
console.log('not allowed') // and so on
})
(我为所有键(从 A 到 Z、1 到 9 等)做了这个 ^。
顺便说一句,我尝试的所有代码都放入了app.whenReady() 函数中。
好吧,这些都不起作用。我看到了很多其他更抽象方式的文章,但它们也没有奏效。 我实际上也尝试过搜索 npm 包,但我没有找到任何可以解决我的问题的包。
我只需要从我的电子应用程序中完全禁用所有键盘快捷键。还有其他方法(实际上可行)吗?
【问题讨论】:
-
不确定是否是最佳解决方案,但如果您在 alt 键为真时拦截 before-input-event 和 preventDefault 会怎样
-
我该怎么做?你能写一个包含所有细节的答案吗?
-
@pushkin 所以你能写一个更详细的答案吗?
标签: node.js electron keyboard-shortcuts