OLD | NEW |
| (Empty) |
1 <!-- BEGIN AUTHORED CONTENT --> | |
2 <p> | |
3 The keybinding API allows you to add keyboard shortcuts that trigger actions in | |
4 your extension. An action can be opening the browser action or page action popup | |
5 or sending a command to the extension. | |
6 </p> | |
7 <h2 id="manifest">Manifest</h2> | |
8 <p> | |
9 In addition to the "experimental" permission you must declare the "keybinding" | |
10 permission in your extension's manifest to use this API and set manifest_version | |
11 to (at least) 2. | |
12 </p> | |
13 <pre>{ | |
14 "name": "My extension", | |
15 ... | |
16 <b> "permissions": [ | |
17 "experimental", | |
18 "keybinding", | |
19 ]</b>, | |
20 ... | |
21 }</pre> | |
22 <h2 id="usage">Usage</h2> | |
23 <p>The keybinding API allows you to define specific commands, and bind them to a | |
24 default key combination. Each command your extension accepts must be listed in | |
25 the manifest as an attribute of the 'commands' manifest key. Note: Combinations | |
26 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the | |
27 AltGr key.</p> | |
28 <pre>{ | |
29 "name": "My extension", | |
30 ... | |
31 <b> "commands": { | |
32 "toggle-feature-foo": { | |
33 "suggested_key": { | |
34 "default": "Ctrl+Shift+Y", | |
35 "mac": "Command+Shift+Y" | |
36 }, | |
37 "description": "Toggle feature foo" | |
38 }, | |
39 "_execute_browser_action": { | |
40 "suggested_key": { | |
41 "windows": "Ctrl+Shift+Y", | |
42 "mac": "Command+Shift+Y", | |
43 "chromeos": "Ctrl+Shift+U", | |
44 "linux": "Ctrl+Shift+J" | |
45 } | |
46 }, | |
47 "_execute_page_action": { | |
48 "suggested_key": { | |
49 "default": "Ctrl+E" | |
50 "windows": "Alt+P", | |
51 "mac": "Option+P", | |
52 } | |
53 } | |
54 }</b>, | |
55 ... | |
56 }</pre> | |
57 <p>In your background page, you can bind a handler to each of the commands | |
58 defined in the manifest (except for '_execute_browser_action' and | |
59 '_execute_page_action') via onCommand.addListener. For example:</p> | |
60 <pre> | |
61 chrome.experimental.keybinding.onCommand.addListener(function(command) { | |
62 console.log('Command:', command); | |
63 }); | |
64 </pre> | |
65 <p>The '_execute_browser_action' and '_execute_page_action' commands are | |
66 reserved for the action of opening your extension's popups. They won't normally | |
67 generate events that you can handle. If you need to take action based on your | |
68 popup opening, consider listening for an 'onDomReady' event inside your popup's | |
69 code. | |
70 </p> | |
71 <!-- END AUTHORED CONTENT --> | |
OLD | NEW |