我正在编写一个响应键盘快捷键的 Kiosk 模式 Chrome 应用程序。我发现最好的方法是使用 Chrome commands
API .
list .json
{...,
"kiosk_enabled": true,
"kiosk_only": false,
"commands": {
"perform-foo": {
"description": "Performs the Foo action",
"suggested_key": {
"default": "Ctrl+Shift+0"
},
"global": true
}
},
...}
据我从文档中得知,不需要特殊权限。我确保按照文档使用“安全”组合键,并认为我会为它指定 global
。
主.js
chrome.commands.onCommand.addListener(function(command) {
if (command == 'perform-foo') {
doFooFunction();
}
}
这在我的 Mac 上作为解压缩的扩展程序工作,但在 ChromeOS 下以单应用 Kiosk 模式或正常 Kiosk 模式启动时不起作用。我还写了一个 test app在信息亭模式下不运行。当我检查 chrome://extensions
中的键盘快捷键时,应用程序似乎已成功地在全局安装了正确的组合键。
是否通过 commands
API 为 kiosk 模式或一般的 CrOS 启用了键盘快捷键?我在这里缺少什么?
最佳答案
来自documentation :
On desktop Chrome, Commands can instead have global scope, as of version 35, and will then also work while Chrome does not have focus. NOTE: The exception here is Chrome OS, where global commands are not allowed at the moment.
我在没有全局选项的情况下在 ChromeOS 的信息亭模式下成功使用了命令。
"commands": {
"perform-foo": {
"description": "Performs the Foo action",
"suggested_key": {
"default": "Ctrl+Shift+0"
}
}
},
关于google-chrome - 在 Kiosk 模式下使用 Chrome 命令 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30857390/