I am creating an electronic application that makes a desktop for a website. I have already registered key bindings on the website, for example Shift+?, which shows a table of all available key bindings.
I need to create application menus that match key bindings. Technically, when a user clicks on a menu item, he has to start key binding on a web page. Example:
When the user clicks Help in the menu → the Shift+?keyword is launched → the web page detects keypress→ the web page shows a table of all registered bindings.
The problem is that I cannot send a binding Shift+?to webContents. These attempts are not performed:
webContents.sendInputEvent({type:'char', keyCode: 'Shift+?' });
webContents.sendInputEvent({type:'keydown', keyCode: 'Shift+?' });
webContents.sendInputEvent({type:'keyup', keyCode: 'Shift+?'});
How to make a web page perform an action based on a specific key binding (aka send a binding to a web page)?
UPD: I learned a few details. The order of events should be keyDown, char, keyUp. I made a convenient function for sending bindings:
function sendKeybinding(win, keyCode) {
win.webContents.sendInputEvent({ type: 'keyDown', keyCode });
win.webContents.sendInputEvent({ type: 'char', keyCode });
win.webContents.sendInputEvent({ type: 'keyUp', keyCode });
}
MenuItemthat uses this might look like this:
{
label: 'Show Keymap',
accelerator: ['Shift+/', '?'],
click(menuItem, browserWindow) {
sendKeybinding(browserWindow, '?');
},
}
There is also a stroke in the case of Shift+?: ?can only be entered when pressed Shift, so there are actually two accelerators Shift+/and ?.
However, I still do not know how to enter keybinding as CmdOrControl+B.