I am building a Chrome extension, and assigned command _execute_browser_action
to Alt+J. I want to simulate this in background.js which listens for all commands using
chrome.commands.onCommand.addListener(function(command) { /* ... */ });
I want _execute_browser_action
to be called through a different command shortcut, say Cmd+Shift+K
In my manifest.json I have declared the following:
"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"
}
}
This is my 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?
}
});
I want to know how to trigger this so that my popup.html opens.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…