【发布时间】:2016-10-25 21:45:26
【问题描述】:
我正在构建一个 Chrome 扩展程序,并将命令 _execute_browser_action 分配给 Alt+J。我想在 background.js 中模拟这个,它使用
chrome.commands.onCommand.addListener(function(command) { /* ... */ });
我希望通过不同的命令快捷方式调用_execute_browser_action,例如 Cmd+Shift+K
在我的 manifest.json 中,我声明了以下内容:
"commands": {
"_execute_browser_action": {
"suggested_key": {
"mac": "Alt+J",
"linux": "Ctrl+Shift+J"
}
},
"asdf" : {
"suggested_key": {
"default": "Ctrl+Shift+K",
"mac": "Command+Shift+K"
},
"description": "asdf"
}
}
这是我的 background.js:
chrome.commands.onCommand.addListener(function(command) {
console.log('onCommand event received for message: ', command);
if (command === "asdf") {
alert("asdf");
var keyPress = jQuery.Event("keypress");
keyPress.altKey = true;
keyPress.ctrlKey = false;
keyPress.which = 74;
//how do I trigger this?
}
});
我想知道如何触发它以便我的 popup.html 打开。
【问题讨论】:
标签: javascript jquery google-chrome-extension keyboard-shortcuts