Pass keyEvent from CEF browser to main application

878 views
Skip to first unread message

Punam Goswami

unread,
Oct 6, 2014, 4:07:15 PM10/6/14
to cef...@googlegroups.com
Hi,

I have a WPF application that opens CEF browser embedded in it. I want to implement some hotkeys functionality like CTRL+C.
The issue I am facing is that if the focus is on the browser window, the main or parent application never gets the keyevent as it is consumed by CEF browser.

Please note that my MultiThreadedMessageLoop is set to true.

I have seen that it needs to be handled in the OnPreKeyEvent of CefKeyboardHandler. This is how my function looks

protected override bool OnPreKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, IntPtr os_event, out bool isKeyboardShortcut)
        {
            isKeyboardShortcut = false;
            if (keyEvent.EventType == CefKeyEventType.RawKeyDown && keyEvent.WindowsKeyCode == 0x43 && keyEvent.Modifiers == CefEventFlags.ControlDown)
            {
                Console.WriteLine("OnPreKeyEvent pressed CTRL+C");
                Console.WriteLine("os_event is {0}", os_event);
                return false;
            }
            
            return true;
        }

Here I understand from the function definition, that we should return true if we are handling keyevent ourselves, else return false in which case it will be handled by the platform or parent application. Please correct me if I am wrong here.

If that is the case, then in the code above , I am returning false on pressing CTRL+C. Still why my MainWindow.xaml.cs file unable to get any of the keyevent.

1. On Returning false from OnPreKeyEvent, control goes to which function for Windows?
2. Why is the os_event coming 0 for me always. Is it something I should be concerned about?


I am finding this problem highly interesting and really keen on finding a solution. Please help.

Thanking,
Punam



Punam Goswami

unread,
Dec 9, 2014, 10:04:13 AM12/9/14
to cef...@googlegroups.com
Hi, 

Someone please help me with this.

any input wil be helpful !!

Regards
Punam
Reply all
Reply to author
Forward
0 new messages