Table of Contents

Class CoreWebView2AcceleratorKeyPressedEventArgs

Namespace
Microsoft.Web.WebView2.Core
Assembly
Microsoft.Web.WebView2.Core.dll

Event args for the AcceleratorKeyPressed event.

public class CoreWebView2AcceleratorKeyPressedEventArgs : EventArgs
Inheritance
CoreWebView2AcceleratorKeyPressedEventArgs
Inherited Members

Properties

Handled

Indicates whether the AcceleratorKeyPressed event is handled by host.

public bool Handled { get; set; }

Property Value

bool

Remarks

For browser accelerator keys, when an accelerator key is pressed, the propagation and processing order is:

  1. A CoreWebView2Controller.AcceleratorKeyPressed event is raised
  2. WebView2 browser feature accelerator key handling
  3. Web Content Handling: If the key combination isn't reserved for browser actions, the key event propagates to the web content, where JavaScript event listeners can capture and respond to it.

If Handled property is set to true anywhere along the path, the event propagation stops, and web content will not receive the key and this prevents the WebView from performing the default action for this accelerator key. Otherwise the WebView will perform the default action for the accelerator key.

IsBrowserAcceleratorKeyEnabled

This IsBrowserAcceleratorKeyEnabled property allows developers to control whether the browser handles accelerator keys such as Ctrl+P or F3, etc.

public bool IsBrowserAcceleratorKeyEnabled { get; set; }

Property Value

bool

Remarks

The CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled API is a convenient setting for developers to disable all the browser accelerator keys together. This setting also sets the default value for the IsBrowserAcceleratorKeyEnabled property.

By default, CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled is TRUE and IsBrowserAcceleratorKeyEnabled is TRUE. When developers change CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled setting to FALSE, this will change default value for IsBrowserAcceleratorKeyEnabled to FALSE. If developers want specific keys to be handled by the browser after changing the CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled setting to FALSE, they need to enable these keys by setting IsBrowserAcceleratorKeyEnabled to TRUE.

The CoreWebView2Controller.AcceleratorKeyPressed event is raised any time an accelerator key is pressed, regardless of whether accelerator keys are enabled or not.

This API will give the event arg higher priority over the CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled setting when we handle the keys.

With IsBrowserAcceleratorKeyEnabled property, if developers mark IsBrowserAcceleratorKeyEnabled as FALSE, the browser will skip the WebView2 browser feature accelerator key handling process, but the event propagation continues, and web content will receive the key combination.

This property does not disable accelerator keys related to movement and text editing, such as:

  • Home, End, Page Up, and Page Down
  • Ctrl-X, Ctrl-C, Ctrl-V
  • Ctrl-A for Select All
  • Ctrl-Z for Undo

KeyEventKind

Gets the key event kind that caused the event to run.

public CoreWebView2KeyEventKind KeyEventKind { get; }

Property Value

CoreWebView2KeyEventKind

KeyEventLParam

Gets the LPARAM value that accompanied the window message.

public int KeyEventLParam { get; }

Property Value

int

Remarks

See the documentation for the WM_KEYDOWN and WM_KEYUP messages.

PhysicalKeyStatus

Gets a CoreWebView2PhysicalKeyStatus representing the information passed in the LPARAM of the window message.

public CoreWebView2PhysicalKeyStatus PhysicalKeyStatus { get; }

Property Value

CoreWebView2PhysicalKeyStatus

VirtualKey

Gets the Win32 virtual key code of the key that was pressed or released.

public uint VirtualKey { get; }

Property Value

uint

Remarks

It is one of the Win32 virtual key constants such as VK_RETURN or an (uppercase) ASCII value such as 'A'. Verify whether Ctrl or Alt are pressed by running GetKeyState(VK_CONTROL) or GetKeyState(VK_MENU).