diff --git a/v2/internal/ffenestri/ffenestri_windows.cpp b/v2/internal/ffenestri/ffenestri_windows.cpp index 5e8767ed3..5d15b6e07 100644 --- a/v2/internal/ffenestri/ffenestri_windows.cpp +++ b/v2/internal/ffenestri/ffenestri_windows.cpp @@ -328,7 +328,6 @@ void completed(struct Application* app) { messageFromWindowCallback(readyMessage.c_str()); } - // bool initWebView2(struct Application *app, int debugEnabled, messageCallback cb) { diff --git a/v2/internal/ffenestri/wv2ComHandler_windows.h b/v2/internal/ffenestri/wv2ComHandler_windows.h index d2817c918..e270d55ef 100644 --- a/v2/internal/ffenestri/wv2ComHandler_windows.h +++ b/v2/internal/ffenestri/wv2ComHandler_windows.h @@ -12,7 +12,8 @@ class wv2ComHandler : public ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, public ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, public ICoreWebView2WebMessageReceivedEventHandler, - public ICoreWebView2PermissionRequestedEventHandler + public ICoreWebView2PermissionRequestedEventHandler, + public ICoreWebView2AcceleratorKeyPressedEventHandler { struct Application *app; @@ -44,6 +45,7 @@ class wv2ComHandler ICoreWebView2 *webview; ::EventRegistrationToken token; controller->get_CoreWebView2(&webview); + controller->add_AcceleratorKeyPressed(this, &token); webview->add_WebMessageReceived(this, &token); webview->add_PermissionRequested(this, &token); @@ -51,6 +53,39 @@ class wv2ComHandler return S_OK; } + // This is our keyboard callback method + HRESULT STDMETHODCALLTYPE Invoke(ICoreWebView2Controller *controller, ICoreWebView2AcceleratorKeyPressedEventArgs * args) { + COREWEBVIEW2_KEY_EVENT_KIND kind; + args->get_KeyEventKind(&kind); + if (kind == COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN || + kind == COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_DOWN) + { +// UINT key; +// args->get_VirtualKey(&key); +// printf("Got key: %d\n", key); + args->put_Handled(TRUE); + // Check if the key is one we want to handle. +// if (std::function action = +// m_appWindow->GetAcceleratorKeyFunction(key)) +// { +// // Keep the browser from handling this key, whether it's autorepeated or +// // not. +// CHECK_FAILURE(args->put_Handled(TRUE)); +// +// // Filter out autorepeated keys. +// COREWEBVIEW2_PHYSICAL_KEY_STATUS status; +// CHECK_FAILURE(args->get_PhysicalKeyStatus(&status)); +// if (!status.WasKeyDown) +// { +// // Perform the action asynchronously to avoid blocking the +// // browser process's event queue. +// m_appWindow->RunAsync(action); +// } +// } + } + return S_OK; + } + // This is called when JS posts a message back to webkit HRESULT STDMETHODCALLTYPE Invoke( ICoreWebView2 *sender, ICoreWebView2WebMessageReceivedEventArgs *args) {