I saw this thread on the official forum of Chromium Embedded Framework but it seems that there were no solutions given. To be honest, I'm not comfortable with C++ platform. Could you help me provide a snippet that binds CEF to the webapp.
I wanted to control the application using the default controls:
ALT+F4 - close
F5 - refresh browser
Short Version: Implement
CefKeyboardHandler
, specificallyOnPreKeyEvent()
This follows the
CefClient
project, whereClientHandler
implementsCefKeyboardHandler
. Checkclient_handler_win.cpp
Longer version follows...
Looking at this thread - Keyboard events "eaten" by browser - this stands out:
There are now two options:
Intercept the key-press before it is sent to the CEF engine, which would require quite a little bit of digging into CEF and be platform specific.
Capture the key-press using a normal Javascript event handler, and callback to C++.
Intercept the key-press before the CEF engine processes it if CEF has such interfaces - this would ideally be platform independant.
Capture Keypress at Native-App level
On a windows machine, I tried searching for
WM_KEYDOWN
which is the usual practice in capturing key events (See Here). I was unable to get any hits on theCefClient
project I was running, so this was a dead end.Anybody with further info on this, please edit and add to this.
Capture Keypress in JS and callback to C++
Once the keypress goes into
CefBrowser
, we could always use Javascript to capture the keypress we want and then call an app handler, like so:Communicating between JS and C++ is done through either V8Extensions, or by binding a Function to the CefContext. Further info at Javascript Integration
This comes with some pitfalls - your event-capturer is 'just another Javascript event handler', and with that comes all the uncertainties of when it is called (before or after other event handlers) and so on. Thankfully, CEF has a nifty little
CefKeyboardHandler
just to do what you want!Intercept Keypress using
CefKeyboardHandler
See
cef_keyboard_handler.h
- the doc forOnPreKeyEvent()
says:From here, it's pretty straightforward. The
CefEventHandle
resolves to a platform specific (sadly - oh well!) standard WindowsMSG
. Note that Alt+F4 is a special system command:Full text at MSDN