OSX CefKeyEvent to offscreen renderer only partially working

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

OSX CefKeyEvent to offscreen renderer only partially working

Postby simonpearce » Wed Mar 01, 2017 2:51 pm

CEF 2704 64bit OSX.

working with a colleague to get macOS keyboard events working in offscreen renderer. my application gives me an NSEvent and i transform that into a CefKeyEvent.

i have modified their windows code to what's below but i don't see my keys appear in the search form on google home page for example.

however, if i visit this javascript test page http://unixpapa.com/js/testkey.html and hit keys, i see the same results as in my desktop browser when pressing/releasing keys.

anyone know what piece i'm missing to make keyboard input work normally?

Code: Select all
CefKeyEvent keyEvent;
if ([ns_event type] == NSKeyDown)
{
    keyEvent.type = KEYEVENT_KEYDOWN;
}
else
if ([ns_event type] == NSKeyUp)
{
    keyEvent.type = KEYEVENT_KEYUP;
}

NSString *c = [ns_event characters];
if ([c length] > 0)
{
    keyEvent.character = [c characterAtIndex:0];
}

NSString *cim = [ns_event charactersIgnoringModifiers];
if ([cim length] > 0)
{
    keyEvent.unmodified_character = [cim characterAtIndex:0];
}

keyEvent.native_key_code = [ns_event keyCode];
keyEvent.modifiers = EVENTFLAG_NONE;

_browser->GetHost()->SendKeyEvent(keyEvent);

simonpearce
Techie
 
Posts: 30
Joined: Tue Oct 27, 2015 2:32 pm

Re: OSX CefKeyEvent to offscreen renderer only partially wor

Postby magreenblatt » Wed Mar 01, 2017 2:54 pm

magreenblatt
Site Admin
 
Posts: 10748
Joined: Fri May 29, 2009 6:57 pm

Re: OSX CefKeyEvent to offscreen renderer only partially wor

Postby simonpearce » Wed Mar 01, 2017 3:14 pm

that was where I pulled my macOS code from.

i must have missed a step and was hoping someone who'd got it working might spot it quickly - i'll delve deeper into that example.
simonpearce
Techie
 
Posts: 30
Joined: Tue Oct 27, 2015 2:32 pm

Re: OSX CefKeyEvent to offscreen renderer only partially wor

Postby simonpearce » Wed Mar 01, 2017 6:28 pm

i think I figured it out after combing the cefclient source. this partial fragment worked for me and displays text as you type, arrows, shift, control etc. work:

Code: Select all
NSEvent* ns_event = (NSEvent*)event;

if (([ns_event type] == NSKeyDown) || ([ns_event type] == NSKeyUp))
{
    CefKeyEvent keyEvent;
   
    NSString *c = [ns_event characters];
    if ([c length] > 0)
    {
        keyEvent.character = [c characterAtIndex:0];
    }
   
    NSString *cim = [ns_event charactersIgnoringModifiers];
    if ([cim length] > 0)
    {
        keyEvent.unmodified_character = [cim characterAtIndex:0];
    }
   
    keyEvent.native_key_code = [ns_event keyCode];
    keyEvent.is_system_key = false;
    keyEvent.modifiers = modifiers;

    if ([ns_event type] == NSKeyDown)
    {
        keyEvent.type =  KEYEVENT_KEYDOWN;
        _browser->GetHost()->SendKeyEvent(keyEvent);

        keyEvent.type =  KEYEVENT_CHAR;
        _browser->GetHost()->SendKeyEvent(keyEvent);
    }
    else
    if ([ns_event type] == NSKeyUp)
    {
        keyEvent.type =  KEYEVENT_KEYUP;
    }
}


i left out the code to transform the modifiers in the NSEvent into a CefKeyEvent but that's easy.

hope it's useful to someone else.
simonpearce
Techie
 
Posts: 30
Joined: Tue Oct 27, 2015 2:32 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 1 guest