-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to send "Enter" keypress event? #8977
Comments
The Closing since it is expected behavior. |
@zcbenz The document said:
Accelerator said:
I think it's clear but wrong in document. And you have already support |
Unfortunately I don't think it's clear at all. What does the structure that gets sent to sendInputEvent for the Enter or Return key look like? I'm trying to build a virtual keyboard for a kiosk and no permutation or combination of values I send produces the desired result. I either get EnteEnte or an exception thrown because some code under the hood doesn't like the event object I send. This definitely doesn't work:
|
@jbmonroe I had this issue too, the electron documentation is flawed here! To workaround this, I had to use RobotJS to simulate some special keys: // keyData.key is coming from a function call from a different location, which gets passed to a webview in React
let inputEventToPass = {
type: 'char',
keyCode: keyData.key
};
if ( keyData.key === 'ENTER') {
inputEventToPass = {
type: 'char',
keyCode: '\u000d',
// @ts-ignore
charCode: 13
};
}
if ( keyData.key === 'BACKSPACE') {
let robot = require('robotjs');
robot.keyTap('backspace');
/*
// does not work
inputEventToPass = {
type: 'char',
keyCode: 'Backspace'
};
*/
return;
}
if ( keyData.key === 'DELETE') {
let robot = require('robotjs');
robot.keyTap('delete');
/*
// does not work
inputEventToPass = {
type: 'char',
keyCode: 'Delete'
};
*/
return;
}
// @ts-ignore
this.webviewRef.current.sendInputEvent(inputEventToPass); @zcbenz maybe there should be a statement in the documentation, that these special keys are not "sendable", or a hint how to actually send these keys/chars. |
I could probably live without the Enter key but the lack of Page Up and Page Down makes the customer and the users unhappy. I'll look into RobotJS to see how much fuss would be involved in adding it to the project (we're just about to completion and the interval before we upload the "final" release is very short). For future projects, this could be exactly what I need. Thanks for pointing this out to me! |
This issue should be re-opened. The documentation is NOT clear Trying to send Enter and Backspace is a nightmare with the current documentation. According to the docs, Also, all the examples above reference a If you truly believe the documentation is clear, lets have a 1-1 conversation |
Expected behavior
And no text written in input box.
Actual behavior
And text "EnteEnte" written in input box
How to reproduce
BTW: I found a workaround by reading the source code:
sendInputEvent({type: 'char', keyCode: String.fromCharCode(0x0D)})
, but sending a string instead of an Enter keypress withsendInputEvent({ type: 'char', keyCode: 'Enter' })
is not what I expected.The text was updated successfully, but these errors were encountered: