Problem with tab/enter keys in OSR mode

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.

Problem with tab/enter keys in OSR mode

Postby Czarek » Fri Sep 13, 2013 3:56 am

Hi Marshall,

Character keys do work fine (abc..), but special keys like tab/enter/pageup/pagedown do not work.
Tab and Enter do not work in editable fields. Pageup and pagedown don't work on pages.
I'm doing it the same as in the cefclient_osr_widget_gtk.cpp in the glarea_key_event() function:

Code: Select all
  key_event.native_key_code = event->keyval;
  key_event.modifiers = get_cef_state_modifiers(event->state);

  if (event->type == GDK_KEY_PRESS) {
    key_event.type = KEYEVENT_RAWKEYDOWN;
    host->SendKeyEvent(key_event);
  } else {
    // Need to send both KEYUP and CHAR events.
    key_event.type = KEYEVENT_KEYUP;
    host->SendKeyEvent(key_event);
    key_event.type = KEYEVENT_CHAR;
    host->SendKeyEvent(key_event);
  }


What am I missing?

This is what is sent when pressing the Tab key on an editable field (google.com):

Code: Select all
keydown keyEvent: {'native_key_code': 9, 'modifiers': 0, 'type': 0}
keyup keyEvent: {'native_key_code': 9, 'modifiers': 0, 'type': 2}
char keyEvent: {'native_key_code': 9, 'modifiers': 0, 'type': 3}


Using CEF 3, branch 1453, revision 1352, on Ubuntu 12.04 64-bit.

Thanks,
Czarek
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

Re: Problem with tab/enter keys in OSR mode

Postby magreenblatt » Fri Sep 13, 2013 7:40 am

Do the keys work in cefclient?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Problem with tab/enter keys in OSR mode

Postby Czarek » Fri Sep 13, 2013 7:59 am

magreenblatt wrote:Do the keys work in cefclient?

When running ./cefclient --off-screen-rendering-enabled - yes it works.

I suspect that this issue might be caused by passing a NULL value when calling SetAsOffscreen(),
as this is in my case, there is no window provided, thus translating the keys may not work correctly.
Do you think this could be a possible cause? If so, would there be any solution for that? I'm using
the Kivy framework and there is no way to get the native handle of the window.
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

Re: Problem with tab/enter keys in OSR mode

Postby magreenblatt » Fri Sep 13, 2013 8:33 am

You should try changing cefclient to pass NULL into SetAsOffScreen to prove or disprove your hypothesis.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Problem with tab/enter keys in OSR mode

Postby Czarek » Fri Sep 13, 2013 9:04 am

magreenblatt wrote:You should try changing cefclient to pass NULL into SetAsOffScreen to prove or disprove your hypothesis.

After changing to NULL in cefclient it still works fine :)
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

Re: Problem with tab/enter keys in OSR mode

Postby Czarek » Fri Sep 13, 2013 9:21 am

I've debugged cefclient further.

When pressing a-z the key codes (event->keyval) are normal: for a = 97, for z = 122.

When pressing tab, the key code = 65289 (in Kivy tab = 9).
For enter = 65293 (kivy = 13), for Page up = 65365 (kivy = 280), for pgdn = 65366 (281).

For tab and enter the difference seems to be the same (=65280), but for pgup/pgdn it is
65085.

Looks like I need to create a translation table for all the keys. Or maybe is there some logic
behind these numbers?

EDIT. It's strange that I can't use modifier constants (EVENTFLAG_SHIFT_DOWN). When pressing
"a" key code is 97, when pressing shift+a then it is 65 => shouldn't this be 97 + pass the
EVENTFLAG_SHIFT_DOWN to the keyEvent.modifiers? Why does the key code change its value
when shift is applied? The same happens for right alt.
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

Re: Problem with tab/enter keys in OSR mode

Postby Czarek » Sat Sep 14, 2013 4:19 am

I had to create key mappings for about 200 keys.. (including shift and right alt combinations),
here is the function for that:

Code: Select all
def translate_to_cef_keycode(self, keycode):
        cef_keycode = keycode
        if self.is_alt2:
            # The key mappings here for right alt were tested
            # with the utf-8 charset on a webpage. If the charset
            # is different there is a chance they won't work correctly.
            alt2_map = {
                    # tilde
                    "96":172,
                    # 0-9 (48..57)
                    "48":125, "49":185, "50":178, "51":179, "52":188,
                    "53":189, "54":190, "55":123, "56":91, "57":93,
                    # minus
                    "45":92,
                    # a-z (97..122)
                    "97":433, "98":2771, "99":486, "100":240, "101":490,
                    "102":496, "103":959, "104":689, "105":2301, "106":65121,
                    "107":930, "108":435, "109":181, "110":497, "111":243,
                    "112":254, "113":64, "114":182, "115":438, "116":956,
                    "117":2302, "118":2770, "119":435, "120":444, "121":2299,
                    "122":447,
                    }
            if str(keycode) in alt2_map:
                cef_keycode = alt2_map[str(keycode)]
            else:
                print("Kivy to CEF key mapping not found (right alt), " \
                        "key code = %s" % keycode)
            shift_alt2_map = {
                    # tilde
                    "96":172,
                    # 0-9 (48..57)
                    "48":176, "49":161, "50":2755, "51":163, "52":36,
                    "53":2756, "54":2757, "55":2758, "56":2761, "57":177,
                    # minus
                    "45":191,
                    # A-Z (97..122)
                    "97":417, "98":2769, "99":454, "100":208, "101":458,
                    "102":170, "103":957, "104":673, "105":697, "106":65122,
                    "107":38, "108":419, "109":186, "110":465, "111":211,
                    "112":222, "113":2009, "114":174, "115":422, "116":940,
                    "117":2300, "118":2768, "119":419, "120":428, "121":165,
                    "122":431,
                    # special: <>?  :"  {}
                    "44":215, "46":247, "47":65110,
                    "59":65113, "39":65114,
                    "91":65112, "93":65108,
                    }
            if self.is_shift1 or self.is_shift2:
                if str(keycode) in shift_alt2_map:
                    cef_keycode = shift_alt2_map[str(keycode)]
                else:
                    print("Kivy to CEF key mapping not found " \
                            "(shift + right alt), key code = %s" % keycode)
        elif self.is_shift1 or self.is_shift2:
            shift_map = {
                    # tilde
                    "96":126,
                    # 0-9 (48..57)
                    "48":41, "49":33, "50":64, "51":35, "52":36, "53":37,
                    "54":94, "55":38, "56":42, "57":40,
                    # minus, plus
                    "45":95, "61":43,
                    # a-z (97..122)
                    "97":65, "98":66, "99":67, "100":68, "101":69, "102":70,
                    "103":71, "104":72, "105":73, "106":74, "107":75, "108":76,
                    "109":77, "110":78, "111":79, "112":80, "113":81, "114":82,
                    "115":83, "116":84, "117":85, "118":86, "119":87, "120":88,
                    "121":89, "122":90,
                    # special: <>?  :"  {}
                    "44":60, "46":62, "47":63,
                    "59":58, "39":34,
                    "91":123, "93":125,
            }
            if str(keycode) in shift_map:
                cef_keycode = shift_map[str(keycode)]
        # Other keys:
        other_keys_map = {
            # Escape
            "27":65307,
            # F1-F12
            "282":65470, "283":65471, "284":65472, "285":65473,
            "286":65474, "287":65475, "288":65476, "289":65477,
            "290":65478, "291":65479, "292":65480, "293":65481,
            # Tab
            "9":65289,
            # Left Shift, Right Shift
            "304":65505, "303":65506,
            # Left Ctrl, Right Ctrl
            "306":65507, "305": 65508,
            # Left Alt, Right Alt
            "308":65513, "313":65027,
            # Backspace
            "8":65288,
            # Enter
            "13":65293,
            # PrScr, ScrLck, Pause
            "316":65377, "302":65300, "19":65299,
            # Insert, Delete,
            # Home, End,
            # Pgup, Pgdn
            "277":65379, "127":65535,
            "278":65360, "279":65367,
            "280":65365, "281":65366,
            # Arrows (left, up, right, down)
            "276":65361, "273":65362, "275":65363, "274":65364,
        }
        if str(keycode) in other_keys_map:
            cef_keycode = other_keys_map[str(keycode)]
        return cef_keycode
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

Re: Problem with tab/enter keys in OSR mode

Postby AndrewH » Fri Sep 05, 2014 12:44 am

Hi Czarek,

Did you get any more insight into this problem?

I'm getting a very similar situation. I'm having to manually change the codes (eg for lower / upper case) before posting the Cef Keyboard event.

In my case though, I have another symptom which is that I can't get some keys to map at all. ie the full stop / period seems to want to behave as a DEL key regardless of what I do.

Ironically I only need a couple of non alphanumeric keys and I'd quite happily filter the others out. But @ and . are needed to enter email addresses.

I also pass NULL into SetAsWindowsless ( was SetAsOffscreen? ), and like you, had also tried changing CEFClient to do the same. Same result. CefClient works fine.

I've written about it on this thread but haven't had any responses. Since writing that I've updated to version 1809, thinking that could be the issue but it made no difference.

Hoping you can help me see what's happening. This is really getting old. (literally and figuratively.)

Regards,
Andrew
AndrewH
Techie
 
Posts: 10
Joined: Sun Aug 17, 2014 10:33 pm

Re: Problem with tab/enter keys in OSR mode

Postby Czarek » Fri Sep 05, 2014 6:10 am

Have you tried using KEYEVENT_KEYDOWN instead of KEYEVENT_RAWKEYDOWN? I saw someone modifying my scripts with this change being made along with getting rid of shift/alt key mappings. Dunno whether this solves the problem of alt/shift key mappings, or whether that person didn't need these mappings in his app.
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

Re: Problem with tab/enter keys in OSR mode

Postby AndrewH » Tue Sep 09, 2014 7:23 pm

Hi Czarek,

Yes I've tried it and it doesn't seem to make any difference.

Thanks very much for your reply.
AndrewH
Techie
 
Posts: 10
Joined: Sun Aug 17, 2014 10:33 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 104 guests