Accelerators and sendInputEvent

Viewed 748

According to the Accelerator documentation, I should be able to send key commands like Ctrl+A and Return.

Using the following, I can send key commands one at a time:

//ch = current key command, like 'a' or 'Backspace'
webView.sendInputEvent({
  type: 'keyDown',
  keyCode: ch
});

webView.sendInputEvent({
  type: 'char',
  keyCode: ch
});

webView.sendInputEvent({
  type: 'keyUp',
  keyCode: ch
});

This works fine for ordinary letter keypresses, and even Backspace, but the above won't honor modifier combinations like Ctrl+A, or even some single modifiers like Return or Enter. If I enter text on a textarea and then send Return, I would expect a newline to be added to the textarea.

From the Electron documentation (emphasis mine):

keyCode String (required) - The character that will be sent as the keyboard event. Should only use the valid key codes in Accelerator.

It would seem by that documentation, the newline should get added.

Is that expectation correct? If so, what am I doing wrong?

0 Answers
Related