回答

1

键盘快捷键可以使用manifest.jsoncommands添加。您可以添加通用操作的键盘快捷键,浏览器操作按钮(_execute_browser_action)或页面操作按钮(_execute_page_action)。

示例的manifest.json包括在所述Chrome documentation含量(略作修改,以反映对于Ctrl键请求 - - ):

"commands": { 
    "toggle-feature-foo": { 
    "suggested_key": { 
     "default": "Ctrl+Shift+B", 
     "mac": "Command+Shift+B" 
    }, 
    "description": "Toggle feature foo" 
    }, 
    "_execute_browser_action": { 
    "suggested_key": { 
     "windows": "Ctrl+Shift+Y", 
     "mac": "Command+Shift+Y", 
     "chromeos": "Ctrl+Shift+U", 
     "linux": "Ctrl+Shift+J" 
    } 
    }, 
    "_execute_page_action": { 
    "suggested_key": { 
     "default": "Ctrl+Shift+E", 
     "windows": "Alt+Shift+P", 
     "mac": "Alt+Shift+P" 
    } 
    } 
}, 

toggle-feature-foo是通用。您可以更改* manifest.json的”关键是你的愿望是什么,它在作为参数传递给你的听众chrome.commands.onCommand通过

在你的背景,你的脚本就可以了(来自同一来源修改):

chrome.commands.onCommand.addListener(function(command) { 
    console.log('Command:', command); 
    if(command === 'toggle-feature-foo') { 
     //Code for toggle-feature-foo 
    } 
}); 

除非Mac触控板手势也会生成键盘按键序列,否则无法轻松捕捉到这些手势,您可能可以编写内容脚本来实现这一点,但如果您必须使用内容脚本来执行所以,这可能是每个网页上的一个重要负担,只是为了启用该功能。

+0

非常感谢。我们的想法是,我可以将热键配置为与Chrome内置热键(如使用Ctrl + Shift + T)重叠吗?无论如何,这正是我所期待的。 –

+0

此外,用户可以通过chrome:// extensions/configureCommands更改它们 –