Merge pull request #9852 from electron/webcontents-ignorekeyboardshortcuts

Add webContents.setIgnoreMenuShortcuts()
This commit is contained in:
Kevin Sawicki 2017-06-28 10:35:02 -07:00 committed by GitHub
commit 4958771b8a
8 changed files with 60 additions and 18 deletions

View file

@ -288,7 +288,22 @@ Returns:
Emitted before dispatching the `keydown` and `keyup` events in the page.
Calling `event.preventDefault` will prevent the page `keydown`/`keyup` events
from being dispatched.
and the menu shortcuts.
To only prevent the menu shortcuts, use
[`setIgnoreMenuShortcuts`](#contentssetignoremenushortcuts):
```javascript
const {BrowserWindow} = require('electron')
let win = new BrowserWindow({width: 800, height: 600})
win.webContents.on('before-input-event', (event, input) => {
// For example, only enable application menu keyboard shortcuts when
// Ctrl/Cmd are down.
win.webContents.setIgnoreMenuShortcuts(!input.control && !input.meta)
})
```
#### Event: 'devtools-opened'
@ -730,6 +745,12 @@ contents.executeJavaScript('fetch("https://jsonplaceholder.typicode.com/users/1"
})
```
#### `contents.setIgnoreMenuShortcuts(ignore)` _Experimental_
* `ignore` Boolean
Ignore application menu shortcuts while this web contents is focused.
#### `contents.setAudioMuted(muted)`
* `muted` Boolean