CEF: cef_binary_112.3.0+gb09c4ca+chromium-112.0.5615.165_linux64.tar.bz2
Hey, I am trying to send key events using the C API running a headless browser. I am rendering the headless browser using the data from the on_paint callback. I have been testing to make sure the key events are properly sent by loading the https://keyboard-test.space/ webpage and when I press keys the webpage indicates they are correctly being pressed as seen in the screenshot below. The problem is that when I click on a form and try to input keys no letters/symbols are being input into forms. I can however Ctrl-V paste, backspace, and enter. Enter will submit whatever form I am typing into, and backspace will delete any characters copied into the form. I can't figure out why no characters are being input into forms when I send key. Is there anything obviously wrong with my key_event struct that I am building?
function for sending the key event:
- Code: Select all
void send_keys(custom_client_t* client, int pressed, int keysym, keyboard_state* kbd_state) {
/* Get previous Keyboard state to check for modifiers and what is pressed */
pthread_mutex_lock(&kbd_state->mutex);
int previous_key_state = kbd_state->key_state[keysym];
int key_modifiers = get_modifiers(kbd_state);
kbd_state->key_state[keysym] = pressed;
pthread_mutex_unlock(&kbd_state->mutex);
/* Convert keysym to native key code */
int native_key_code = guac_keysym_to_native_key_code(keysym);
/* Set the key event type based on the current and previous key state */
cef_key_event_t key_event = {};
if (pressed) {
if (previous_key_state == 1) {
key_event.type = KEYEVENT_KEYDOWN;
} else {
key_event.type = KEYEVENT_RAWKEYDOWN;
}
} else {
key_event.type = KEYEVENT_KEYUP;
}
key_event.native_key_code = native_key_code;
key_event.windows_key_code = native_key_code;
key_event.character = keysym_to_unicode_char(keysym);
key_event.unmodified_character = keysym_to_unicode_char(keysym);
key_event.modifiers = key_modifiers;
/* Send the key event to the browser */
cef_browser_host_t *browser_host = client->life_span_handler->browser->get_host(client->life_span_handler->browser);
browser_host->send_key_event(browser_host, &key_event);
fprintf(stderr, "CEF: [Key Event] type: %d, keysym: %d, native_key_code: %d, character: %c, modifiers: %d\n",
key_event.type, keysym, native_key_code, key_event.character, key_modifiers);
}
Logs when I type Hello, World!:
- Code: Select all
CEF: [Key Event] type: 0, keysym: 72, native_key_code: 72, character: H, modifiers: 2
CEF: [Key Event] type: 2, keysym: 72, native_key_code: 72, character: H, modifiers: 2
CEF: [Key Event] type: 2, keysym: 65505, native_key_code: 16, character: 0, modifiers: 2
CEF: [Key Event] type: 0, keysym: 101, native_key_code: 69, character: e, modifiers: 0
CEF: [Key Event] type: 2, keysym: 101, native_key_code: 69, character: e, modifiers: 0
CEF: [Key Event] type: 0, keysym: 108, native_key_code: 76, character: l, modifiers: 0
CEF: [Key Event] type: 2, keysym: 108, native_key_code: 76, character: l, modifiers: 0
CEF: [Key Event] type: 0, keysym: 108, native_key_code: 76, character: l, modifiers: 0
CEF: [Key Event] type: 2, keysym: 108, native_key_code: 76, character: l, modifiers: 0
CEF: [Key Event] type: 0, keysym: 111, native_key_code: 79, character: o, modifiers: 0
CEF: [Key Event] type: 2, keysym: 111, native_key_code: 79, character: o, modifiers: 0
CEF: [Key Event] type: 0, keysym: 44, native_key_code: 188, character: ,, modifiers: 0
CEF: [Key Event] type: 2, keysym: 44, native_key_code: 188, character: ,, modifiers: 0
CEF: [Key Event] type: 0, keysym: 32, native_key_code: 32, character: , modifiers: 0
CEF: [Key Event] type: 2, keysym: 32, native_key_code: 32, character: , modifiers: 0
CEF: [Key Event] type: 0, keysym: 65505, native_key_code: 16, character: 0, modifiers: 0
CEF: [Key Event] type: 0, keysym: 87, native_key_code: 87, character: W, modifiers: 2
CEF: [Key Event] type: 2, keysym: 65505, native_key_code: 16, character: 0, modifiers: 2
CEF: [Key Event] type: 0, keysym: 111, native_key_code: 79, character: o, modifiers: 0
CEF: [Key Event] type: 2, keysym: 111, native_key_code: 79, character: o, modifiers: 0
CEF: [Key Event] type: 0, keysym: 114, native_key_code: 82, character: r, modifiers: 0
CEF: [Key Event] type: 2, keysym: 114, native_key_code: 82, character: r, modifiers: 0
CEF: [Key Event] type: 0, keysym: 108, native_key_code: 76, character: l, modifiers: 0
CEF: [Key Event] type: 0, keysym: 100, native_key_code: 68, character: d, modifiers: 0
CEF: [Key Event] type: 2, keysym: 108, native_key_code: 76, character: l, modifiers: 0
CEF: [Key Event] type: 2, keysym: 100, native_key_code: 68, character: d, modifiers: 0
CEF: [Key Event] type: 0, keysym: 65505, native_key_code: 16, character: 0, modifiers: 0
CEF: [Key Event] type: 0, keysym: 33, native_key_code: 49, character: !, modifiers: 2
CEF: [Key Event] type: 2, keysym: 33, native_key_code: 49, character: !, modifiers: 2
CEF: [Key Event] type: 2, keysym: 65505, native_key_code: 16, character: 0, modifiers: 2