mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 00:29:36 +08:00
[windows] Add key handler for Webview2 to prevent default hotkeys.
This commit is contained in:
parent
d574d53fca
commit
b552c16539
@ -328,7 +328,6 @@ void completed(struct Application* app) {
|
||||
messageFromWindowCallback(readyMessage.c_str());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
bool initWebView2(struct Application *app, int debugEnabled, messageCallback cb) {
|
||||
|
||||
|
@ -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<void()> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user