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