Send XKeyEvent to cef by CefBrowserHost::SendKeyEvent?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Send XKeyEvent to cef by CefBrowserHost::SendKeyEvent?

Postby king » Thu Oct 17, 2019 4:39 am

Hi All
I am now trying to resend the XKeyEvent i get to cef using CefBrowserHost::SendKeyEvent. But i still have some issues I am struggling with. With most printable keys like 'b'
'c', I can get it sent to cef correctly, However, character like 'r' never get sent to cef. With non-printable keys like Caps Lock and Backspace, cef got characters in the editable field as well, take backspace key as an example, when i press backspace key, I got '(' in the text field. Whats wrong with my code or is there any example of converting XKeyEvent to CefKeyEvent in linux? Here is the code snippet:

....
XNextEvent(display, &e)
case KeyPress:
XLookupString(&e.xkey, buffer, bufsize, &keysym, &compose);
evt.type = KEYEVENT_RAWKEYDOWN;
evt.modifiers = CefGetKeyboardModifiers(e.xkey.state);
evt.windows_key_code = e.xkey.keycode;
evt.native_key_code = e.xkey.keycode;
evt.is_system_key = 0;
evt.character = keysym;
evt.unmodified_character = keysym;
browser_host->SendKeyEvent(evt);
case KeyRelease:
XLookupString(&e.xkey, buffer, bufsize, &keysym, &compose);
evt.type = KEYEVENT_KEYUP;
evt.modifiers = CefGetKeyboardModifiers(e.xkey.state);
evt.windows_key_code = e.xkey.keycode;
evt.native_key_code = e.xkey.keycode;
evt.is_system_key = 0;
evt.character = keysym;
evt.unmodified_character = keysym;
browser_host->SendKeyEvent(evt);

evt.type = KEYEVENT_CHAR
browser_host->SendKeyEvent(evt);
....
king
Techie
 
Posts: 18
Joined: Wed Nov 14, 2018 3:41 am

Re: Send XKeyEvent to cef by CefBrowserHost::SendKeyEvent?

Postby Czarek » Thu Oct 17, 2019 4:57 am

KEYEVENT_CHAR should be sent only for text characters such as a-z. It should be sent after RAWKEYDOWN and before KEYUP. Maybe look at Chromium source code: https://cs.chromium.org/chromium/src/ui ... 6d089ba9db
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 218 guests