CWebView::KeyEventHandled Method  
 
BOOL KeyEventHandled(
  BOOL bHandled  
);

The KeyEventHandled method sets an accelerator key event as handled.

Parameters

bHandled
An integer which specifies if the accelerator key event was handled by the application. A non-zero value indicates the application has handled the accelerator key event and the WebView2 control should not process the event. A value of zero specifies that the browser should handle the accelerator key using it's normal, default behavior.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The KeyEventHandled method is used in conjunction with the WebViewEventProc callback when the application receives a WEBVIEW_EVENT_ACCELERATOR_KEYPRESS event. By calling this method and specifying that the key event has been handled, the application can prevent the browser from processing the key itself.

This mechanism is useful when you want to disable or override the default behavior of certain keys within the embedded browser. For example, you may wish to prevent the user from pressing F12 to open the developer tools, block function keys that have meaning in your application, or intercept combinations such as Ctrl+P or Ctrl+S to substitute your own print or save functionality.

If bHandled is non-zero, the event is considered handled by the host application and WebView2 will not process the key. If bHandled is zero, the key is passed through and processed normally according to the browser's default behavior. This method should typically be called during the event handler for WEBVIEW_EVENT_ACCELERATOR_KEYPRESS.

Note that this method only affects accelerator key events when the WEBVIEW_OPTION_ENABLE_ACCELERATORS option has been specified when creating or attaching the WebView. It does not apply to ordinary text input within form fields or content editable regions in the page.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also